10
10
import math
11
11
import copy
12
12
13
- from matplotlib import lines as mlines , axis as maxis , \
14
- patches as mpatches
13
+ from matplotlib import lines as mlines , axis as maxis , patches as mpatches
15
14
from matplotlib import rcParams
16
15
from . import art3d
17
16
from . import proj3d
@@ -40,8 +39,8 @@ def move_from_center(coord, centers, deltas, axmask=(True, True, True)):
40
39
def tick_update_position (tick , tickxs , tickys , labelpos ):
41
40
'''Update tick line and label position and style.'''
42
41
43
- for (label , on ) in (( tick .label1 , tick .label1On ), \
44
- (tick .label2 , tick .label2On )) :
42
+ for (label , on ) in [( tick .label1 , tick .label1On ),
43
+ (tick .label2 , tick .label2On )] :
45
44
if on :
46
45
label .set_position (labelpos )
47
46
@@ -81,68 +80,57 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
81
80
# Do not depend on this existing in future releases!
82
81
self ._axinfo = self ._AXINFO [adir ].copy ()
83
82
if rcParams ['_internal.classic_mode' ]:
84
- self ._axinfo .update ({'label' :
85
- {'va' : 'center' ,
86
- 'ha' : 'center' },
87
- 'tick' :
88
- {'inward_factor' : 0.2 ,
89
- 'outward_factor' : 0.1 ,
90
- 'linewidth' : rcParams ['lines.linewidth' ],
91
- 'color' : 'k' },
92
- 'axisline' :
93
- {'linewidth' : 0.75 ,
94
- 'color' : (0 , 0 , 0 , 1 )},
95
- 'grid' :
96
- {'color' : (0.9 , 0.9 , 0.9 , 1 ),
97
- 'linewidth' : 1.0 ,
98
- 'linestyle' : '-' },
99
- })
83
+ self ._axinfo .update (
84
+ {'label' : {'va' : 'center' ,
85
+ 'ha' : 'center' },
86
+ 'tick' : {'inward_factor' : 0.2 ,
87
+ 'outward_factor' : 0.1 ,
88
+ 'linewidth' : rcParams ['lines.linewidth' ],
89
+ 'color' : 'k' },
90
+ 'axisline' : {'linewidth' : 0.75 ,
91
+ 'color' : (0 , 0 , 0 , 1 )},
92
+ 'grid' : {'color' : (0.9 , 0.9 , 0.9 , 1 ),
93
+ 'linewidth' : 1.0 ,
94
+ 'linestyle' : '-' },
95
+ })
100
96
else :
101
- self ._axinfo .update ({'label' :
102
- {'va' : 'center' ,
103
- 'ha' : 'center' },
104
- 'tick' :
105
- {'inward_factor' : 0.2 ,
106
- 'outward_factor' : 0.1 ,
107
- 'linewidth' : rcParams .get (
108
- adir + 'tick.major.width' ,
109
- rcParams ['xtick.major.width' ]),
110
- 'color' : rcParams .get (
111
- adir + 'tick.color' ,
112
- rcParams ['xtick.color' ])},
113
- 'axisline' :
114
- {'linewidth' : rcParams ['axes.linewidth' ],
115
- 'color' : rcParams ['axes.edgecolor' ]},
116
- 'grid' :
117
- {'color' : rcParams ['grid.color' ],
118
- 'linewidth' : rcParams ['grid.linewidth' ],
119
- 'linestyle' : rcParams ['grid.linestyle' ]},
120
- })
121
-
97
+ self ._axinfo .update (
98
+ {'label' : {'va' : 'center' ,
99
+ 'ha' : 'center' },
100
+ 'tick' : {'inward_factor' : 0.2 ,
101
+ 'outward_factor' : 0.1 ,
102
+ 'linewidth' : rcParams .get (
103
+ adir + 'tick.major.width' ,
104
+ rcParams ['xtick.major.width' ]),
105
+ 'color' : rcParams .get (
106
+ adir + 'tick.color' ,
107
+ rcParams ['xtick.color' ])},
108
+ 'axisline' : {'linewidth' : rcParams ['axes.linewidth' ],
109
+ 'color' : rcParams ['axes.edgecolor' ]},
110
+ 'grid' : {'color' : rcParams ['grid.color' ],
111
+ 'linewidth' : rcParams ['grid.linewidth' ],
112
+ 'linestyle' : rcParams ['grid.linestyle' ]},
113
+ })
122
114
123
115
maxis .XAxis .__init__ (self , axes , * args , ** kwargs )
124
-
125
116
self .set_rotate_label (kwargs .get ('rotate_label' , None ))
126
117
127
-
128
118
def init3d (self ):
129
- self .line = mlines .Line2D (xdata = ( 0 , 0 ), ydata = ( 0 , 0 ),
130
- linewidth = self . _axinfo [ 'axisline' ][ 'linewidth' ] ,
131
- color = self ._axinfo ['axisline' ]['color ' ],
132
- antialiased = True ,
133
- )
119
+ self .line = mlines .Line2D (
120
+ xdata = ( 0 , 0 ), ydata = ( 0 , 0 ) ,
121
+ linewidth = self ._axinfo ['axisline' ]['linewidth ' ],
122
+ color = self . _axinfo [ 'axisline' ][ 'color' ] ,
123
+ antialiased = True )
134
124
135
125
# Store dummy data in Polygon object
136
- self .pane = mpatches .Polygon (np .array ([[0 ,0 ], [0 ,1 ], [1 ,0 ], [0 ,0 ]]),
137
- closed = False ,
138
- alpha = 0.8 ,
139
- facecolor = (1 ,1 ,1 ,0 ),
140
- edgecolor = (1 ,1 ,1 ,0 ))
126
+ self .pane = mpatches .Polygon (
127
+ np .array ([[0 , 0 ], [0 , 1 ], [1 , 0 ], [0 , 0 ]]),
128
+ closed = False , alpha = 0.8 , facecolor = 'k' , edgecolor = 'k' )
141
129
self .set_pane_color (self ._axinfo ['color' ])
142
130
143
131
self .axes ._set_artist_props (self .line )
144
132
self .axes ._set_artist_props (self .pane )
145
- self .gridlines = art3d .Line3DCollection ([], )
133
+ self .gridlines = art3d .Line3DCollection ([])
146
134
self .axes ._set_artist_props (self .gridlines )
147
135
self .axes ._set_artist_props (self .label )
148
136
self .axes ._set_artist_props (self .offsetText )
@@ -153,7 +141,8 @@ def init3d(self):
153
141
def get_tick_positions (self ):
154
142
majorLocs = self .major .locator ()
155
143
self .major .formatter .set_locs (majorLocs )
156
- majorLabels = [self .major .formatter (val , i ) for i , val in enumerate (majorLocs )]
144
+ majorLabels = [self .major .formatter (val , i )
145
+ for i , val in enumerate (majorLocs )]
157
146
return majorLabels , majorLocs
158
147
159
148
def get_major_ticks (self , numticks = None ):
@@ -173,7 +162,7 @@ def set_pane_pos(self, xys):
173
162
self .stale = True
174
163
175
164
def set_pane_color (self , color ):
176
- '''Set pane color to a RGBA tuple'''
165
+ '''Set pane color to a RGBA tuple. '''
177
166
self ._axinfo ['color' ] = color
178
167
self .pane .set_edgecolor (color )
179
168
self .pane .set_facecolor (color )
@@ -211,8 +200,8 @@ def _get_coord_info(self, renderer):
211
200
212
201
vals = mins [0 ], maxs [0 ], mins [1 ], maxs [1 ], mins [2 ], maxs [2 ]
213
202
tc = self .axes .tunit_cube (vals , renderer .M )
214
- avgz = [tc [p1 ][2 ] + tc [p2 ][2 ] + tc [p3 ][2 ] + tc [p4 ][2 ] for \
215
- p1 , p2 , p3 , p4 in self ._PLANES ]
203
+ avgz = [tc [p1 ][2 ] + tc [p2 ][2 ] + tc [p3 ][2 ] + tc [p4 ][2 ]
204
+ for p1 , p2 , p3 , p4 in self ._PLANES ]
216
205
highs = np .array ([avgz [2 * i ] < avgz [2 * i + 1 ] for i in range (3 )])
217
206
218
207
return mins , maxs , centers , deltas , tc , highs
@@ -301,13 +290,13 @@ def draw(self, renderer):
301
290
ax_points_estimate = sum (72. * ax_inches )
302
291
deltas_per_point = 48. / ax_points_estimate
303
292
default_offset = 21.
304
- labeldeltas = (self . labelpad + default_offset ) * deltas_per_point \
305
- * deltas
293
+ labeldeltas = (
294
+ ( self . labelpad + default_offset ) * deltas_per_point * deltas )
306
295
axmask = [True , True , True ]
307
296
axmask [index ] = False
308
297
lxyz = move_from_center (lxyz , centers , labeldeltas , axmask )
309
- tlx , tly , tlz = proj3d .proj_transform (lxyz [0 ], lxyz [1 ], lxyz [2 ], \
310
- renderer .M )
298
+ tlx , tly , tlz = proj3d .proj_transform (lxyz [0 ], lxyz [1 ], lxyz [2 ],
299
+ renderer .M )
311
300
self .label .set_position ((tlx , tly ))
312
301
if self .get_rotate_label (self .label .get_text ()):
313
302
angle = art3d .norm_text_angle (math .degrees (math .atan2 (dy , dx )))
@@ -425,26 +414,28 @@ def draw(self, renderer):
425
414
# Get tick line positions
426
415
pos = copy .copy (edgep1 )
427
416
pos [index ] = loc
428
- pos [tickdir ] = edgep1 [tickdir ] + info ['tick' ]['outward_factor' ] * \
429
- ticksign * tickdelta
430
- x1 , y1 , z1 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ], \
431
- renderer .M )
432
- pos [tickdir ] = edgep1 [tickdir ] - info ['tick' ]['inward_factor' ] * \
433
- ticksign * tickdelta
434
- x2 , y2 , z2 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ], \
435
- renderer .M )
417
+ pos [tickdir ] = (
418
+ edgep1 [tickdir ]
419
+ + info ['tick' ]['outward_factor' ] * ticksign * tickdelta )
420
+ x1 , y1 , z1 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
421
+ renderer .M )
422
+ pos [tickdir ] = (
423
+ edgep1 [tickdir ]
424
+ - info ['tick' ]['inward_factor' ] * ticksign * tickdelta )
425
+ x2 , y2 , z2 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
426
+ renderer .M )
436
427
437
428
# Get position of label
438
429
default_offset = 8. # A rough estimate
439
- labeldeltas = (tick . get_pad () + default_offset ) * deltas_per_point \
440
- * deltas
430
+ labeldeltas = (
431
+ ( tick . get_pad () + default_offset ) * deltas_per_point * deltas )
441
432
442
433
axmask = [True , True , True ]
443
434
axmask [index ] = False
444
435
pos [tickdir ] = edgep1 [tickdir ]
445
436
pos = move_from_center (pos , centers , labeldeltas , axmask )
446
- lx , ly , lz = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ], \
447
- renderer .M )
437
+ lx , ly , lz = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
438
+ renderer .M )
448
439
449
440
tick_update_position (tick , (x1 , x2 ), (y1 , y2 ), (lx , ly ))
450
441
tick .tick1line .set_linewidth (info ['tick' ]['linewidth' ])
0 commit comments