@@ -148,8 +148,6 @@ def __init__(self, axes, loc, label=None,
148
148
grid_alpha = mpl .rcParams ["grid.alpha" ]
149
149
grid_kw = {k [5 :]: v for k , v in kw .items ()}
150
150
151
- self .apply_tickdir (tickdir )
152
-
153
151
self .tick1line = mlines .Line2D (
154
152
[], [],
155
153
color = color , linestyle = "none" , zorder = zorder , visible = tick1On ,
@@ -174,6 +172,9 @@ def __init__(self, axes, loc, label=None,
174
172
self .label2 = mtext .Text (
175
173
np .nan , np .nan ,
176
174
fontsize = labelsize , color = labelcolor , visible = label2On )
175
+
176
+ self ._apply_tickdir (tickdir )
177
+
177
178
for meth , attr in [("_get_tick1line" , "tick1line" ),
178
179
("_get_tick2line" , "tick2line" ),
179
180
("_get_gridline" , "gridline" ),
@@ -209,15 +210,22 @@ def _set_labelrotation(self, labelrotation):
209
210
_api .check_in_list (['auto' , 'default' ], labelrotation = mode )
210
211
self ._labelrotation = (mode , angle )
211
212
212
- def apply_tickdir (self , tickdir ):
213
+ def _apply_tickdir (self , tickdir ):
213
214
"""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.
214
219
if tickdir is None :
215
220
tickdir = mpl .rcParams [f'{ self .__name__ } .direction' ]
216
221
_api .check_in_list (['in' , 'out' , 'inout' ], tickdir = tickdir )
217
222
self ._tickdir = tickdir
218
223
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 ()
219
228
self .stale = True
220
- # Subclass overrides should compute _tickmarkers as appropriate here.
221
229
222
230
def get_tickdir (self ):
223
231
return self ._tickdir
@@ -363,15 +371,13 @@ def _apply_params(self, **kw):
363
371
# convenient to leave it here.
364
372
self ._width = kw .pop ('width' , self ._width )
365
373
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 ))
371
377
for line in (self .tick1line , self .tick2line ):
372
378
line .set_markersize (self ._size )
373
379
line .set_markeredgewidth (self ._width )
374
- # _get_text1_transform uses _pad from apply_tickdir .
380
+ # _get_text1_transform uses _pad from _apply_tickdir .
375
381
trans = self ._get_text1_transform ()[0 ]
376
382
self .label1 .set_transform (trans )
377
383
trans = self ._get_text2_transform ()[0 ]
@@ -419,20 +425,13 @@ class XTick(Tick):
419
425
def __init__ (self , * args , ** kwargs ):
420
426
super ().__init__ (* args , ** kwargs )
421
427
# x in data coords, y in axes coords
428
+ ax = self .axes
422
429
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" ))
427
431
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" ))
432
433
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" ))
436
435
# the y loc is 3 points below the min of y axis
437
436
trans , va , ha = self ._get_text1_transform ()
438
437
self .label1 .set (
@@ -451,15 +450,16 @@ def _get_text1_transform(self):
451
450
def _get_text2_transform (self ):
452
451
return self .axes .get_xaxis_text2_transform (self ._pad )
453
452
454
- def apply_tickdir (self , tickdir ):
453
+ def _apply_tickdir (self , tickdir ):
455
454
# docstring inherited
456
- super ().apply_tickdir (tickdir )
457
- self . _tickmarkers = {
455
+ super ()._apply_tickdir (tickdir )
456
+ mark1 , mark2 = {
458
457
'out' : (mlines .TICKDOWN , mlines .TICKUP ),
459
458
'in' : (mlines .TICKUP , mlines .TICKDOWN ),
460
459
'inout' : ('|' , '|' ),
461
460
}[self ._tickdir ]
462
- self .stale = True
461
+ self .tick1line .set_marker (mark1 )
462
+ self .tick2line .set_marker (mark2 )
463
463
464
464
def update_position (self , loc ):
465
465
"""Set the location of tick in data coords with scalar *loc*."""
@@ -486,20 +486,13 @@ class YTick(Tick):
486
486
def __init__ (self , * args , ** kwargs ):
487
487
super ().__init__ (* args , ** kwargs )
488
488
# x in axes coords, y in data coords
489
+ ax = self .axes
489
490
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" ))
494
492
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" ))
499
494
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" ))
503
496
# the y loc is 3 points below the min of y axis
504
497
trans , va , ha = self ._get_text1_transform ()
505
498
self .label1 .set (
@@ -518,15 +511,16 @@ def _get_text1_transform(self):
518
511
def _get_text2_transform (self ):
519
512
return self .axes .get_yaxis_text2_transform (self ._pad )
520
513
521
- def apply_tickdir (self , tickdir ):
514
+ def _apply_tickdir (self , tickdir ):
522
515
# docstring inherited
523
- super ().apply_tickdir (tickdir )
524
- self . _tickmarkers = {
516
+ super ()._apply_tickdir (tickdir )
517
+ mark1 , mark2 = {
525
518
'out' : (mlines .TICKLEFT , mlines .TICKRIGHT ),
526
519
'in' : (mlines .TICKRIGHT , mlines .TICKLEFT ),
527
520
'inout' : ('_' , '_' ),
528
521
}[self ._tickdir ]
529
- self .stale = True
522
+ self .tick1line .set_marker (mark1 )
523
+ self .tick2line .set_marker (mark2 )
530
524
531
525
def update_position (self , loc ):
532
526
"""Set the location of tick in data coords with scalar *loc*."""
0 commit comments