Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e410b1b

Browse filesBrowse files
committed
Copy all internals from initial Tick to lazy ones
Fixes #28574
1 parent cc71085 commit e410b1b
Copy full SHA for e410b1b

File tree

2 files changed

+38
-5
lines changed
Filter options

2 files changed

+38
-5
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+16-5Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,21 @@ def _set_labelrotation(self, labelrotation):
198198
_api.check_in_list(['auto', 'default'], labelrotation=mode)
199199
self._labelrotation = (mode, angle)
200200

201+
@property
202+
def _pad(self):
203+
return self._base_pad + self.get_tick_padding()
204+
201205
def _apply_tickdir(self, tickdir):
202206
"""Set tick direction. Valid values are 'out', 'in', 'inout'."""
203-
# This method is responsible for updating `_pad`, and, in subclasses,
204-
# for setting the tick{1,2}line markers as well. From the user
205-
# perspective this should always be called through _apply_params, which
206-
# further updates ticklabel positions using the new pads.
207+
# This method is responsible for verifying input and, in subclasses, for setting
208+
# the tick{1,2}line markers. From the user perspective this should always be
209+
# called through _apply_params, which further updates ticklabel positions using
210+
# the new pads.
207211
if tickdir is None:
208212
tickdir = mpl.rcParams[f'{self.__name__}.direction']
209213
else:
210214
_api.check_in_list(['in', 'out', 'inout'], tickdir=tickdir)
211215
self._tickdir = tickdir
212-
self._pad = self._base_pad + self.get_tick_padding()
213216

214217
def get_tickdir(self):
215218
return self._tickdir
@@ -1615,6 +1618,14 @@ def _copy_tick_props(self, src, dest):
16151618
dest.tick1line.update_from(src.tick1line)
16161619
dest.tick2line.update_from(src.tick2line)
16171620
dest.gridline.update_from(src.gridline)
1621+
self.update_from(src)
1622+
dest._loc = src._loc
1623+
dest._size = src._size
1624+
dest._width = src._width
1625+
dest._base_pad = src._base_pad
1626+
dest._labelrotation = src._labelrotation
1627+
dest._zorder = src._zorder
1628+
dest._tickdir = src._tickdir
16181629

16191630
def get_label_text(self):
16201631
"""Get the text of the label."""

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5741,6 +5741,28 @@ def test_reset_ticks(fig_test, fig_ref):
57415741
ax.yaxis.reset_ticks()
57425742

57435743

5744+
@mpl.style.context('mpl20')
5745+
def test_context_ticks():
5746+
with plt.rc_context({
5747+
'xtick.direction': 'in', 'xtick.major.size': 30, 'xtick.major.width': 5,
5748+
'xtick.color': 'C0', 'xtick.major.pad': 12,
5749+
'xtick.bottom': True, 'xtick.top': True,
5750+
'xtick.labelsize': 14, 'xtick.labelcolor': 'C1'}):
5751+
fig, ax = plt.subplots()
5752+
# Draw outside the context so that all-but-first tick are generated with the normal
5753+
# mpl20 style in place.
5754+
fig.draw_without_rendering()
5755+
5756+
first_tick = ax.xaxis.majorTicks[0]
5757+
for tick in ax.xaxis.majorTicks[1:]:
5758+
assert tick._size == first_tick._size
5759+
assert tick._width == first_tick._width
5760+
assert tick._base_pad == first_tick._base_pad
5761+
assert tick._labelrotation == first_tick._labelrotation
5762+
assert tick._zorder == first_tick._zorder
5763+
assert tick._tickdir == first_tick._tickdir
5764+
5765+
57445766
def test_vline_limit():
57455767
fig = plt.figure()
57465768
ax = fig.gca()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.