Skip to content

FIX: Always update tick labels (fixes #9397) #9452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,11 +1052,12 @@ def _update_ticks(self, renderer):
for tick, loc, label in tick_tups:
if tick is None:
continue
if not mtransforms.interval_contains(interval_expanded, loc):
continue
# NB: always update labels and position to avoid issues like #9397
tick.update_position(loc)
tick.set_label1(label)
tick.set_label2(label)
if not mtransforms.interval_contains(interval_expanded, loc):
continue
ticks_to_draw.append(tick)

return ticks_to_draw
Expand Down
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4570,6 +4570,25 @@ def test_set_get_ticklabels():
ax[1].set_yticklabels(ax[0].get_yticklabels())


def test_tick_label_update():
# test issue 9397

fig, ax = plt.subplots()

# Set up a dummy formatter
def formatter_func(x, pos):
return "unit value" if x == 1 else ""
ax.xaxis.set_major_formatter(plt.FuncFormatter(formatter_func))

# Force some of the x-axis ticks to be outside of the drawn range
ax.set_xticks([-1, 0, 1, 2, 3])
ax.set_xlim(-0.5, 2.5)

ax.figure.canvas.draw()
tick_texts = [tick.get_text() for tick in ax.xaxis.get_ticklabels()]
assert tick_texts == ["", "", "unit value", "", ""]


@image_comparison(baseline_images=['o_marker_path_snap'], extensions=['png'],
savefig_kwarg={'dpi': 72})
def test_o_marker_path_snap():
Expand Down