8000 Modify set_ticklabels() to fix counterintuitive behavior of set_ticklabels(get_ticklabels)#2246 by MirandaXM · Pull Request #4141 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Modify set_ticklabels() to fix counterintuitive behavior of set_ticklabels(get_ticklabels)#2246 #4141

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
Feb 22, 2015
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
16 changes: 14 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,8 +1521,20 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
tick locations, regardless of the state of label1On and
label2On.

ACCEPTS: sequence of strings
"""
ACCEPTS: sequence of strings or Text objects
"""
get_labels = []
for t in ticklabels:
# try calling get_text() to check whether it is Text object
# if it is Text, get label content
try:
get_labels.append(t.get_text())
# otherwise add the label to the list directly
except AttributeError:
get_labels.append(t)
# replace the ticklabels list with the processed one
ticklabels = get_labels

minor = kwargs.pop('minor', False)
if minor:
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import numpy as np
from numpy import ma
from numpy import arange

import matplotlib
from matplotlib.testing.decorators import image_comparison, cleanup
Expand Down Expand Up @@ -3476,6 +3477,28 @@ def test_pie_frame_grid():
plt.axis('equal')


@image_comparison(baseline_images=['set_get_ticklabels'], extensions=['png'])
def test_set_get_ticklabels():
# test issue 2246
fig, ax = plt.subplots(2)
ha = ['normal', 'set_x/yticklabels']

ax[0].plot(arange(10))
ax[0].set_title(ha[0])

ax[1].plot(arange(10))
ax[1].set_title(ha[1])

# set ticklabel to 1 plot in normal way
ax[0].set_xticklabels(('a', 'b', 'c', 'd'))
ax[0].set_yticklabels(('11', '12', '13', '14'))

# set ticklabel to the other plot, expect the 2 plots have same label setting
# pass get_ticklabels return value as ticklabels argument
ax[1].set_xticklabels(ax[0].get_xticklabels() )
ax[1].set_yticklabels(ax[0].get_yticklabels() )


@cleanup
def test_margins():
# test all ways margins can be called
Expand Down
0