@@ -148,8 +148,6 @@ def __init__(self, axes, loc, label=None,
148148 grid_alpha = mpl .rcParams ["grid.alpha" ]
149149 grid_kw = {k [5 :]: v for k , v in kw .items ()}
150150
151- self .apply_tickdir (tickdir )
152-
153151 self .tick1line = mlines .Line2D (
154152 [], [],
155153 color = color , linestyle = "none" , zorder = zorder , visible = tick1On ,
@@ -174,6 +172,9 @@ def __init__(self, axes, loc, label=None,
174172 self .label2 = mtext .Text (
175173 np .nan , np .nan ,
176174 fontsize = labelsize , color = labelcolor , visible = label2On )
175+
176+ self ._apply_tickdir (tickdir )
177+
177178 for meth , attr in [("_get_tick1line" , "tick1line" ),
178179 ("_get_tick2line" , "tick2line" ),
179180 ("_get_gridline" , "gridline" ),
@@ -209,15 +210,22 @@ def _set_labelrotation(self, labelrotation):
209210 _api .check_in_list (['auto' , 'default' ], labelrotation = mode )
210211 self ._labelrotation = (mode , angle )
211212
212- def apply_tickdir (self , tickdir ):
213+ def _apply_tickdir (self , tickdir ):
213214 """Set tick direction. Valid values are 'out', 'in', 'inout'."""
215+ # This method is responsible for updating `_pad`, and, in subclasses,
216+ # for setting the tick{1,2}line markers as well. From the user
217+ # perspective this should always be called though _apply_params, which
218+ # further updates ticklabel positions using the new pads.
214219 if tickdir is None :
215220 tickdir = mpl .rcParams [f'{ self .__name__ } .direction' ]
216221 _api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
217222 self ._tickdir = tickdir
218223 self ._pad = self ._base_pad + self .get_tick_padding ()
224+
225+ @_api .deprecated ("3.5" , alternative = "axis.set_tick_params" )
226+ def apply_tickdir (self , tickdir ):
227+ self ._apply_tickdir ()
219228 self .stale = True
220- # Subclass overrides should compute _tickmarkers as appropriate here.
221229
222230 def get_tickdir (self ):
223231 return self ._tickdir
@@ -363,15 +371,13 @@ def _apply_params(self, **kw):
363371 # convenient to leave it here.
364372 self ._width = kw .pop ('width' , self ._width )
365373 self ._base_pad = kw .pop ('pad' , self ._base_pad )
366- # apply_tickdir uses _size and _base_pad to make _pad,
367- # and also makes _tickmarkers.
368- self .apply_tickdir (kw .pop ('tickdir' , self ._tickdir ))
369- self .tick1line .set_marker (self ._tickmarkers [0 ])
370- self .tick2line .set_marker (self ._tickmarkers [1 ])
374+ # _apply_tickdir uses _size and _base_pad to make _pad, and also
375+ # sets the ticklines markers.
376+ self ._apply_tickdir (kw .pop ('tickdir' , self ._tickdir ))
371377 for line in (self .tick1line , self .tick2line ):
372378 line .set_markersize (self ._size )
373379 line .set_markeredgewidth (self ._width )
374- # _get_text1_transform uses _pad from apply_tickdir .
380+ # _get_text1_transform uses _pad from _apply_tickdir .
375381 trans = self ._get_text1_transform ()[0 ]
376382 self .label1 .set_transform (trans )
377383 trans = self ._get_text2_transform ()[0 ]
@@ -419,20 +425,13 @@ class XTick(Tick):
419425 def __init__ (self , * args , ** kwargs ):
420426 super ().__init__ (* args , ** kwargs )
421427 # x in data coords, y in axes coords
428+ ax = self .axes
422429 self .tick1line .set (
423- xdata = [0 ], ydata = [0 ],
424- transform = self .axes .get_xaxis_transform (which = "tick1" ),
425- marker = self ._tickmarkers [0 ],
426- )
430+ data = ([0 ], [0 ]), transform = ax .get_xaxis_transform ("tick1" ))
427431 self .tick2line .set (
428- xdata = [0 ], ydata = [1 ],
429- transform = self .axes .get_xaxis_transform (which = "tick2" ),
430- marker = self ._tickmarkers [1 ],
431- )
432+ data = ([0 ], [1 ]), transform = ax .get_xaxis_transform ("tick2" ))
432433 self .gridline .set (
433- xdata = [0 , 0 ], ydata = [0 , 1 ],
434- transform = self .axes .get_xaxis_transform (which = "grid" ),
435- )
434+ data = ([0 , 0 ], [0 , 1 ]), transform = ax .get_xaxis_transform ("grid" ))
436435 # the y loc is 3 points below the min of y axis
437436 trans , va , ha = self ._get_text1_transform ()
438437 self .label1 .set (
@@ -451,15 +450,16 @@ def _get_text1_transform(self):
451450 def _get_text2_transform (self ):
452451 return self .axes .get_xaxis_text2_transform (self ._pad )
453452
454- def apply_tickdir (self , tickdir ):
453+ def _apply_tickdir (self , tickdir ):
455454 # docstring inherited
456- super ().apply_tickdir (tickdir )
457- self . _tickmarkers = {
455+ super ()._apply_tickdir (tickdir )
456+ mark1 , mark2 = {
458457 'out' : (mlines .TICKDOWN , mlines .TICKUP ),
459458 'in' : (mlines .TICKUP , mlines .TICKDOWN ),
460459 'inout' : ('|' , '|' ),
461460 }[self ._tickdir ]
462- self .stale = True
461+ self .tick1line .set_marker (mark1 )
462+ self .tick2line .set_marker (mark2 )
463463
464464 def update_position (self , loc ):
465465 """Set the location of tick in data coords with scalar *loc*."""
@@ -486,20 +486,13 @@ class YTick(Tick):
486486 def __init__ (self , * args , ** kwargs ):
487487 super ().__init__ (* args , ** kwargs )
488488 # x in axes coords, y in data coords
489+ ax = self .axes
489490 self .tick1line .set (
490- xdata = [0 ], ydata = [0 ],
491- transform = self .axes .get_yaxis_transform (which = "tick1" ),
492- marker = self ._tickmarkers [0 ],
493- )
491+ data = ([0 ], [0 ]), transform = ax .get_yaxis_transform ("tick1" ))
494492 self .tick2line .set (
495- xdata = [1 ], ydata = [0 ],
496- transform = self .axes .get_yaxis_transform (which = "tick2" ),
497- marker = self ._tickmarkers [1 ],
498- )
493+ data = ([1 ], [0 ]), transform = ax .get_yaxis_transform ("tick2" ))
499494 self .gridline .set (
500- xdata = [0 , 1 ], ydata = [0 , 0 ],
501- transform = self .axes .get_yaxis_transform (which = "grid" ),
502- )
495+ data = ([0 , 1 ], [0 , 0 ]), transform = ax .get_yaxis_transform ("grid" ))
503496 # the y loc is 3 points below the min of y axis
504497 trans , va , ha = self ._get_text1_transform ()
505498 self .label1 .set (
@@ -518,15 +511,16 @@ def _get_text1_transform(self):
518511 def _get_text2_transform (self ):
519512 return self .axes .get_yaxis_text2_transform (self ._pad )
520513
521- def apply_tickdir (self , tickdir ):
514+ def _apply_tickdir (self , tickdir ):
522515 # docstring inherited
523- super ().apply_tickdir (tickdir )
524- self . _tickmarkers = {
516+ super ()._apply_tickdir (tickdir )
517+ mark1 , mark2 = {
525518 'out' : (mlines .TICKLEFT , mlines .TICKRIGHT ),
526519 'in' : (mlines .TICKRIGHT , mlines .TICKLEFT ),
527520 'inout' : ('_' , '_' ),
528521 }[self ._tickdir ]
529- self .stale = True
522+ self .tick1line .set_marker (mark1 )
523+ self .tick2line .set_marker (mark2 )
530524
531525 def update_position (self , loc ):
532526 """Set the location of tick in data coords with scalar *loc*."""
0 commit comments