@@ -153,12 +153,10 @@ def get_axislabel_pos_angle(self, axes):
153
153
# TICK
154
154
155
155
def get_tick_transform (self , axes ):
156
- return [axes .get_xaxis_transform (),
157
- axes .get_yaxis_transform ()][self .nth_coord ]
156
+ return [axes .get_xaxis_transform (), axes .get_yaxis_transform ()][self .nth_coord ]
158
157
159
158
160
159
class _FloatingAxisArtistHelperBase (_AxisArtistHelperBase ):
161
-
162
160
def __init__ (self , nth_coord , value ):
163
161
self .nth_coord = nth_coord
164
162
self ._value = value
@@ -168,8 +166,7 @@ def get_nth_coord(self):
168
166
return self .nth_coord
169
167
170
168
def get_line (self , axes ):
171
- raise RuntimeError (
172
- "get_line method should be defined by the derived class" )
169
+ raise RuntimeError ("get_line method should be defined by the derived class" )
173
170
174
171
175
172
class FixedAxisArtistHelperRectilinear (_FixedAxisArtistHelperBase ):
@@ -187,10 +184,7 @@ def __init__(self, axes, loc, nth_coord=None):
187
184
188
185
def get_tick_iterators (self , axes ):
189
186
"""tick_loc, tick_angle, tick_label"""
190
- if self ._loc in ["bottom" , "top" ]:
191
- angle_normal , angle_tangent = 90 , 0
192
- else : # "left", "right"
193
- angle_normal , angle_tangent = 0 , 90
187
+ angle_normal , angle_tangent = {0 : (90 , 0 ), 1 : (0 , 90 )}[self .nth_coord ]
194
188
195
189
major = self .axis .major
196
190
major_locs = major .locator ()
@@ -207,8 +201,7 @@ def _f(locs, labels):
207
201
c = self ._to_xy (loc , const = self ._pos )
208
202
# check if the tick point is inside axes
209
203
c2 = tick_to_axes .transform (c )
210
- if mpl .transforms ._interval_contains_close (
211
- (0 , 1 ), c2 [self .nth_coord ]):
204
+ if mpl .transforms ._interval_contains_close ((0 , 1 ), c2 [self .nth_coord ]):
212
205
yield c , angle_normal , angle_tangent , label
213
206
214
207
return _f (major_locs , major_labels ), _f (minor_locs , minor_labels )
@@ -245,20 +238,14 @@ def get_axislabel_pos_angle(self, axes):
245
238
data_to_axes = axes .transData - axes .transAxes
246
239
p = data_to_axes .transform ([self ._value , self ._value ])
247
240
verts = self ._to_xy (0.5 , const = p [fixed_coord ])
248
- if 0 <= verts [fixed_coord ] <= 1 :
249
- return verts , angle
250
- else :
251
- return None , None
241
+ return (verts , angle ) if 0 <= verts [fixed_coord ] <= 1 else (None , None )
252
242
253
243
def get_tick_transform (self , axes ):
254
244
return axes .transData
255
245
256
246
def get_tick_iterators (self , axes ):
257
247
"""tick_loc, tick_angle, tick_label"""
258
- if self .nth_coord == 0 :
259
- angle_normal , angle_tangent = 90 , 0
260
- else :
261
- angle_normal , angle_tangent = 0 , 90
248
+ angle_normal , angle_tangent = {0 : (90 , 0 ), 1 : (0 , 90 )}[self .nth_coord ]
262
249
263
250
major = self .axis .major
264
251
major_locs = major .locator ()
@@ -326,27 +313,18 @@ def __init__(self, axes):
326
313
327
314
@_api .delete_parameter (
328
315
"3.9" , "nth_coord" , addendum = "'nth_coord' is now inferred from 'loc'." )
329
- def new_fixed_axis (self , loc ,
330
- nth_coord = None ,
331
- axis_direction = None ,
332
- offset = None ,
333
- axes = None ,
334
- ):
316
+ def new_fixed_axis (
317
+ self , loc , nth_coord = None , axis_direction = None , offset = None , axes = None ):
335
318
if axes is None :
336
319
_api .warn_external (
337
320
"'new_fixed_axis' explicitly requires the axes keyword." )
338
321
axes = self .axes
339
322
if axis_direction is None :
340
323
axis_direction = loc
341
- helper = FixedAxisArtistHelperRectilinear (axes , loc )
342
- axisline = AxisArtist (axes , helper , offset = offset ,
343
- axis_direction = axis_direction )
344
- return axisline
324
+ return AxisArtist (axes , FixedAxisArtistHelperRectilinear (axes , loc ),
325
+ offset = offset , axis_direction = axis_direction )
345
326
346
- def new_floating_axis (self , nth_coord , value ,
347
- axis_direction = "bottom" ,
348
- axes = None ,
349
- ):
327
+ def new_floating_axis (self , nth_coord , value , axis_direction = "bottom" , axes = None ):
350
328
if axes is None :
351
329
_api .warn_external (
352
330
"'new_floating_axis' explicitly requires the axes keyword." )
@@ -404,8 +382,7 @@ def __call__(self, *args, **kwargs):
404
382
405
383
def __init__ (self , * args , grid_helper = None , ** kwargs ):
406
384
self ._axisline_on = True
407
- self ._grid_helper = (grid_helper if grid_helper
408
- else GridHelperRectlinear (self ))
385
+ self ._grid_helper = grid_helper if grid_helper else GridHelperRectlinear (self )
409
386
super ().__init__ (* args , ** kwargs )
410
387
self .toggle_axisline (True )
411
388
0 commit comments