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,10 @@ 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``.
644650 """
645651 super ().__init__ ()
646652 self ._remove_overlapping_locs = True
@@ -674,7 +680,12 @@ def __init__(self, axes, *, pickradius=15):
674680 self ._major_tick_kw = dict ()
675681 self ._minor_tick_kw = dict ()
676682
677- self .clear ()
683+ if clear :
684+ self .clear ()
685+ else :
686+ self .converter = None
687+ self .units = None
688+
678689 self ._autoscale_on = True
679690
680691 @property
@@ -2353,8 +2364,6 @@ def set_ticks_position(self, position):
23532364 can be used if you don't want any ticks. 'none' and 'both'
23542365 affect only the ticks, not the labels.
23552366 """
2356- _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2357- position = position )
23582367 if position == 'top' :
23592368 self .set_tick_params (which = 'both' , top = True , labeltop = True ,
23602369 bottom = False , labelbottom = False )
@@ -2377,7 +2386,8 @@ def set_ticks_position(self, position):
23772386 self ._tick_position = 'bottom'
23782387 self .offsetText .set_verticalalignment ('top' )
23792388 else :
2380- assert False , "unhandled parameter not caught by _check_in_list"
2389+ _api .check_in_list (['top' , 'bottom' , 'both' , 'default' , 'none' ],
2390+ position = position )
23812391 self .stale = True
23822392
23832393 def tick_top (self ):
@@ -2599,8 +2609,6 @@ def set_ticks_position(self, position):
25992609 can be used if you don't want any ticks. 'none' and 'both'
26002610 affect only the ticks, not the labels.
26012611 """
2602- _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2603- position = position )
26042612 if position == 'right' :
26052613 self .set_tick_params (which = 'both' , right = True , labelright = True ,
26062614 left = False , labelleft = False )
@@ -2619,7 +2627,8 @@ def set_ticks_position(self, position):
26192627 self .set_tick_params (which = 'both' , right = True , labelright = False ,
26202628 left = True , labelleft = True )
26212629 else :
2622- assert False , "unhandled parameter not caught by _check_in_list"
2630+ _api .check_in_list (['left' , 'right' , 'both' , 'default' , 'none' ],
2631+ position = position )
26232632 self .stale = True
26242633
26252634 def tick_right (self ):
0 commit comments