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 27fd53a

Browse filesBrowse files
committed
always update tick labels (and add a test)
1 parent 7cca455 commit 27fd53a
Copy full SHA for 27fd53a

File tree

Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,11 +1052,12 @@ def _update_ticks(self, renderer):
10521052
for tick, loc, label in tick_tups:
10531053
if tick is None:
10541054
continue
1055-
if not mtransforms.interval_contains(interval_expanded, loc):
1056-
continue
1055+
# NB: always update labels and position to avoid issues like #9397
10571056
tick.update_position(loc)
10581057
tick.set_label1(label)
10591058
tick.set_label2(label)
1059+
if not mtransforms.interval_contains(interval_expanded, loc):
1060+
continue
10601061
ticks_to_draw.append(tick)
10611062

10621063
return ticks_to_draw

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,25 @@ def test_set_get_ticklabels():
45704570
ax[1].set_yticklabels(ax[0].get_yticklabels())
45714571

45724572

4573+
def test_tick_label_update():
4574+
# test issue 9397
4575+
4576+
fig, ax = plt.subplots()
4577+
4578+
# Set up a dummy formatter
4579+
def formatter_func(x, pos):
4580+
return "unit value" if x == 1 else ""
4581+
ax.xaxis.set_major_formatter(plt.FuncFormatter(formatter_func))
4582+
4583+
# Force some of the x-axis ticks to be outside of the drawn range
4584+
ax.set_xticks([-1, 0, 1, 2, 3])
4585+
ax.set_xlim(-0.5, 2.5)
4586+
4587+
ax.figure.canvas.draw()
4588+
tick_texts = [tick.get_text() for tick in ax.xaxis.get_ticklabels()]
4589+
assert tick_texts == ["", "", "unit value", "", ""]
4590+
4591+
45734592
@image_comparison(baseline_images=['o_marker_path_snap'], extensions=['png'],
45744593
savefig_kwarg={'dpi': 72})
45754594
def test_o_marker_path_snap():

0 commit comments

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