3232_gridline_param_names = ['grid_' + name
3333 for name in _line_param_names + _line_param_aliases ]
3434
35+ _MARKER_DICT = {
36+ 'out' : (mlines .TICKDOWN , mlines .TICKUP ),
37+ 'in' : (mlines .TICKUP , mlines .TICKDOWN ),
38+ 'inout' : ('|' , '|' ),
39+ }
40+
3541
3642class Tick (martist .Artist ):
3743 """
@@ -87,11 +93,10 @@ def __init__(
8793 super ().__init__ ()
8894
8995 if gridOn is None :
90- if major and ( mpl .rcParams ['axes.grid.which' ]
91- in ('both' , 'major' )):
96+ which = mpl .rcParams ['axes.grid.which' ]
97+ if major and ( which in ('both' , 'major' )):
9298 gridOn = mpl .rcParams ['axes.grid' ]
93- elif (not major ) and (mpl .rcParams ['axes.grid.which' ]
94- in ('both' , 'minor' )):
99+ elif (not major ) and (which in ('both' , 'minor' )):
95100 gridOn = mpl .rcParams ['axes.grid' ]
96101 else :
97102 gridOn = False
@@ -209,7 +214,8 @@ def _apply_tickdir(self, tickdir):
209214 # further updates ticklabel positions using the new pads.
210215 if tickdir is None :
211216 tickdir = mpl .rcParams [f'{ self .__name__ } .direction' ]
212- _api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
217+ else :
218+ _api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
213219 self ._tickdir = tickdir
214220 self ._pad = self ._base_pad + self .get_tick_padding ()
215221
@@ -436,11 +442,7 @@ def _get_text2_transform(self):
436442 def _apply_tickdir (self , tickdir ):
437443 # docstring inherited
438444 super ()._apply_tickdir (tickdir )
439- mark1 , mark2 = {
440- 'out' : (mlines .TICKDOWN , mlines .TICKUP ),
441- 'in' : (mlines .TICKUP , mlines .TICKDOWN ),
442- 'inout' : ('|' , '|' ),
443- }[self ._tickdir ]
445+ mark1 , mark2 = _MARKER_DICT [self ._tickdir ]
444446 self .tick1line .set_marker (mark1 )
445447 self .tick2line .set_marker (mark2 )
446448
@@ -632,7 +634,7 @@ def __str__(self):
632634 return "{}({},{})" .format (
633635 type (self ).__name__ , * self .axes .transAxes .transform ((0 , 0 )))
634636
635- def __init__ (self , axes , * , pickradius = 15 ):
637+ def __init__ (self , axes , * , pickradius = 15 , clear = True ):
636638 """
637639 Parameters
638640 ----------
@@ -641,6 +643,11 @@ def __init__(self, axes, *, pickradius=15):
641643 pickradius : float
642644 The acceptance radius for containment tests. See also
643645 `.Axis.contains`.
646+ clear : bool, default: True
647+ Whether to clear the Axis on creation. This is not required, e.g., when
648+ creating an Axis as part of an Axes, as ``Axes.clear`` will call
649+ ``Axis.clear``.
650+ .. versionadded:: 3.8
644651 """
645652 super ().__init__ ()
646653 self ._remove_overlapping_locs = True
@@ -674,7 +681,12 @@ def __init__(self, axes, *, pickradius=15):
674681 self ._major_tick_kw = dict ()
675682 self ._minor_tick_kw = dict ()
676683
677- self .clear ()
684+ if clear :
685+ self .clear ()
686+ else :
687+ self .converter = None
688+ self .units = None
689+
678690 self ._autoscale_on = True
679691
680692 @property
@@ -2353,8 +2365,6 @@ def set_ticks_position(self, position):
23532365 can be used if you don't want any ticks. 'none' and 'both'
23542366 affect only the ticks, not the labels.
23552367 """
2356- _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2357- position = position )
23582368 if position == 'top' :
23592369 self .set_tick_params (which = 'both' , top = True , labeltop = True ,
23602370 bottom = False , labelbottom = False )
@@ -2377,7 +2387,8 @@ def set_ticks_position(self, position):
23772387 self ._tick_position = 'bottom'
23782388 self .offsetText .set_verticalalignment ('top' )
23792389 else :
2380- assert False , "unhandled parameter not caught by _check_in_list"
2390+ _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2391+ position = position )
23812392 self .stale = True
23822393
23832394 def tick_top (self ):
@@ -2599,8 +2610,6 @@ def set_ticks_position(self, position):
25992610 can be used if you don't want any ticks. 'none' and 'both'
26002611 affect only the ticks, not the labels.
26012612 """
2602- _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2603- position = position )
26042613 if position == 'right' :
26052614 self .set_tick_params (which = 'both' , right = True , labelright = True ,
26062615 left = False , labelleft = False )
@@ -2619,7 +2628,8 @@ def set_ticks_position(self, position):
26192628 self .set_tick_params (which = 'both' , right = True , labelright = False ,
26202629 left = True , labelleft = True )
26212630 else :
2622- assert False , "unhandled parameter not caught by _check_in_list"
2631+ _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2632+ position = position )
26232633 self .stale = True
26242634
26252635 def tick_right (self ):
0 commit comments