Skip to content

Commit 48b2e65

Browse files
committed
Further simplify apply_tickdir logic by removing _tickmarkers.
... which is otherwise just an attribute to coordinate between _apply_params and _apply_tickdir.
1 parent b20e36c commit 48b2e65

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

lib/matplotlib/axis.py

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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"),
@@ -211,16 +212,20 @@ def _set_labelrotation(self, labelrotation):
211212

212213
def _apply_tickdir(self, tickdir):
213214
"""Set tick direction. Valid values are 'out', 'in', 'inout'."""
214-
# Overriding subclasses should also compute _tickmarkers here.
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.
215219
if tickdir is None:
216220
tickdir = mpl.rcParams[f'{self.__name__}.direction']
217221
_api.check_in_list(['in', 'out', 'inout'], tickdir=tickdir)
218222
self._tickdir = tickdir
219223
self._pad = self._base_pad + self.get_tick_padding()
220-
self.stale = True
221224

222-
apply_tickdir = _api.deprecate_privatize_attribute(
223-
"3.5", alternative="axis.set_tick_params")
225+
@_api.deprecated("3.5", alternative="axis.set_tick_params")
226+
def apply_tickdir(self, tickdir):
227+
self._apply_tickdir()
228+
self.stale = True
224229

225230
def get_tickdir(self):
226231
return self._tickdir
@@ -366,11 +371,9 @@ def _apply_params(self, **kw):
366371
# convenient to leave it here.
367372
self._width = kw.pop('width', self._width)
368373
self._base_pad = kw.pop('pad', self._base_pad)
369-
# _apply_tickdir uses _size and _base_pad to make _pad,
370-
# and also makes _tickmarkers.
374+
# _apply_tickdir uses _size and _base_pad to make _pad, and also
375+
# sets the ticklines markers.
371376
self._apply_tickdir(kw.pop('tickdir', self._tickdir))
372-
self.tick1line.set_marker(self._tickmarkers[0])
373-
self.tick2line.set_marker(self._tickmarkers[1])
374377
for line in (self.tick1line, self.tick2line):
375378
line.set_markersize(self._size)
376379
line.set_markeredgewidth(self._width)
@@ -422,20 +425,13 @@ class XTick(Tick):
422425
def __init__(self, *args, **kwargs):
423426
super().__init__(*args, **kwargs)
424427
# x in data coords, y in axes coords
428+
ax = self.axes
425429
self.tick1line.set(
426-
xdata=[0], ydata=[0],
427-
transform=self.axes.get_xaxis_transform(which="tick1"),
428-
marker=self._tickmarkers[0],
429-
)
430+
data=([0], [0]), transform=ax.get_xaxis_transform("tick1"))
430431
self.tick2line.set(
431-
xdata=[0], ydata=[1],
432-
transform=self.axes.get_xaxis_transform(which="tick2"),
433-
marker=self._tickmarkers[1],
434-
)
432+
data=([0], [1]), transform=ax.get_xaxis_transform("tick2"))
435433
self.gridline.set(
436-
xdata=[0, 0], ydata=[0, 1],
437-
transform=self.axes.get_xaxis_transform(which="grid"),
438-
)
434+
data=([0, 0], [0, 1]), transform=ax.get_xaxis_transform("grid"))
439435
# the y loc is 3 points below the min of y axis
440436
trans, va, ha = self._get_text1_transform()
441437
self.label1.set(
@@ -457,12 +453,13 @@ def _get_text2_transform(self):
457453
def _apply_tickdir(self, tickdir):
458454
# docstring inherited
459455
super()._apply_tickdir(tickdir)
460-
self._tickmarkers = {
456+
mark1, mark2 = {
461457
'out': (mlines.TICKDOWN, mlines.TICKUP),
462458
'in': (mlines.TICKUP, mlines.TICKDOWN),
463459
'inout': ('|', '|'),
464460
}[self._tickdir]
465-
self.stale = True
461+
self.tick1line.set_marker(mark1)
462+
self.tick2line.set_marker(mark2)
466463

467464
def update_position(self, loc):
468465
"""Set the location of tick in data coords with scalar *loc*."""
@@ -489,20 +486,13 @@ class YTick(Tick):
489486
def __init__(self, *args, **kwargs):
490487
super().__init__(*args, **kwargs)
491488
# x in axes coords, y in data coords
489+
ax = self.axes
492490
self.tick1line.set(
493-
xdata=[0], ydata=[0],
494-
transform=self.axes.get_yaxis_transform(which="tick1"),
495-
marker=self._tickmarkers[0],
496-
)
491+
data=([0], [0]), transform=ax.get_yaxis_transform("tick1"))
497492
self.tick2line.set(
498-
xdata=[1], ydata=[0],
499-
transform=self.axes.get_yaxis_transform(which="tick2"),
500-
marker=self._tickmarkers[1],
501-
)
493+
data=([1], [0]), transform=ax.get_yaxis_transform("tick2"))
502494
self.gridline.set(
503-
xdata=[0, 1], ydata=[0, 0],
504-
transform=self.axes.get_yaxis_transform(which="grid"),
505-
)
495+
data=([0, 1], [0, 0]), transform=ax.get_yaxis_transform("grid"))
506496
# the y loc is 3 points below the min of y axis
507497
trans, va, ha = self._get_text1_transform()
508498
self.label1.set(
@@ -524,12 +514,13 @@ def _get_text2_transform(self):
524514
def _apply_tickdir(self, tickdir):
525515
# docstring inherited
526516
super()._apply_tickdir(tickdir)
527-
self._tickmarkers = {
517+
mark1, mark2 = {
528518
'out': (mlines.TICKLEFT, mlines.TICKRIGHT),
529519
'in': (mlines.TICKRIGHT, mlines.TICKLEFT),
530520
'inout': ('_', '_'),
531521
}[self._tickdir]
532-
self.stale = True
522+
self.tick1line.set_marker(mark1)
523+
self.tick2line.set_marker(mark2)
533524

534525
def update_position(self, loc):
535526
"""Set the location of tick in data coords with scalar *loc*."""

0 commit comments

Comments
 (0)