@@ -153,12 +153,10 @@ def get_axislabel_pos_angle(self, axes):
153153 # TICK
154154
155155 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 ]
158157
159158
160159class _FloatingAxisArtistHelperBase (_AxisArtistHelperBase ):
161-
162160 def __init__ (self , nth_coord , value ):
163161 self .nth_coord = nth_coord
164162 self ._value = value
@@ -168,8 +166,7 @@ def get_nth_coord(self):
168166 return self .nth_coord
169167
170168 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" )
173170
174171
175172class FixedAxisArtistHelperRectilinear (_FixedAxisArtistHelperBase ):
@@ -187,10 +184,7 @@ def __init__(self, axes, loc, nth_coord=None):
187184
188185 def get_tick_iterators (self , axes ):
189186 """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 ]
194188
195189 major = self .axis .major
196190 major_locs = major .locator ()
@@ -207,8 +201,7 @@ def _f(locs, labels):
207201 c = self ._to_xy (loc , const = self ._pos )
208202 # check if the tick point is inside axes
209203 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 ]):
212205 yield c , angle_normal , angle_tangent , label
213206
214207 return _f (major_locs , major_labels ), _f (minor_locs , minor_labels )
@@ -245,20 +238,14 @@ def get_axislabel_pos_angle(self, axes):
245238 data_to_axes = axes .transData - axes .transAxes
246239 p = data_to_axes .transform ([self ._value , self ._value ])
247240 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 )
252242
253243 def get_tick_transform (self , axes ):
254244 return axes .transData
255245
256246 def get_tick_iterators (self , axes ):
257247 """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 ]
262249
263250 major = self .axis .major
264251 major_locs = major .locator ()
@@ -326,27 +313,18 @@ def __init__(self, axes):
326313
327314 @_api .delete_parameter (
328315 "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 ):
335318 if axes is None :
336319 _api .warn_external (
337320 "'new_fixed_axis' explicitly requires the axes keyword." )
338321 axes = self .axes
339322 if axis_direction is None :
340323 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 )
345326
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 ):
350328 if axes is None :
351329 _api .warn_external (
352330 "'new_floating_axis' explicitly requires the axes keyword." )
@@ -404,8 +382,7 @@ def __call__(self, *args, **kwargs):
404382
405383 def __init__ (self , * args , grid_helper = None , ** kwargs ):
406384 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 )
409386 super ().__init__ (* args , ** kwargs )
410387 self .toggle_axisline (True )
411388
0 commit comments