12
12
import numpy as np
13
13
14
14
from matplotlib import (
15
- artist , colors as mcolors , lines , text as mtext , path as mpath )
15
+ artist , cbook , colors as mcolors , lines , text as mtext , path as mpath )
16
16
from matplotlib .collections import (
17
17
LineCollection , PolyCollection , PatchCollection , PathCollection )
18
18
from matplotlib .colors import Normalize
@@ -49,13 +49,12 @@ def get_dir_vector(zdir):
49
49
- 'y': equivalent to (0, 1, 0)
50
50
- 'z': equivalent to (0, 0, 1)
51
51
- *None*: equivalent to (0, 0, 0)
52
- - an iterable (x, y, z) is returned unchanged.
52
+ - an iterable (x, y, z) is converted to a NumPy array, if not already
53
53
54
54
Returns
55
55
-------
56
56
x, y, z : array-like
57
- The direction vector. This is either a numpy.array or *zdir* itself if
58
- *zdir* is already a length-3 iterable.
57
+ The direction vector.
59
58
"""
60
59
if zdir == 'x' :
61
60
return np .array ((1 , 0 , 0 ))
@@ -66,7 +65,7 @@ def get_dir_vector(zdir):
66
65
elif zdir is None :
67
66
return np .array ((0 , 0 , 0 ))
68
67
elif np .iterable (zdir ) and len (zdir ) == 3 :
69
- return zdir
68
+ return np . array ( zdir )
70
69
else :
71
70
raise ValueError ("'x', 'y', 'z', None or vector of length 3 expected" )
72
71
@@ -96,21 +95,22 @@ def __init__(self, x=0, y=0, z=0, text='', zdir='z', **kwargs):
96
95
self .set_3d_properties (z , zdir )
97
96
98
97
def set_3d_properties (self , z = 0 , zdir = 'z' ):
99
- x , y = self .get_position ()
100
- self ._position3d = np .array ((x , y , z ))
98
+ self ._z = z
101
99
self ._dir_vec = get_dir_vector (zdir )
102
100
self .stale = True
103
101
104
102
@artist .allow_rasterization
105
103
def draw (self , renderer ):
104
+ position3d = np .array ((self ._x , self ._y , self ._z ))
106
105
proj = proj3d .proj_trans_points (
107
- [self ._position3d , self ._position3d + self ._dir_vec ], renderer .M )
106
+ [position3d , position3d + self ._dir_vec ],
107
+ renderer .M )
108
108
dx = proj [0 ][1 ] - proj [0 ][0 ]
109
109
dy = proj [1 ][1 ] - proj [1 ][0 ]
110
110
angle = math .degrees (math .atan2 (dy , dx ))
111
- self . set_position (( proj [0 ][0 ], proj [1 ][0 ]))
112
- self . set_rotation ( _norm_text_angle (angle ))
113
- mtext .Text .draw (self , renderer )
111
+ with cbook . _setattr_cm ( self , _x = proj [0 ][0 ], _y = proj [1 ][0 ],
112
+ _rotation = _norm_text_angle (angle )):
113
+ mtext .Text .draw (self , renderer )
114
114
self .stale = False
115
115
116
116
def get_tightbbox (self , renderer ):
0 commit comments