-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Keep explicit ticklabels in sync with ticks from FixedLocator #17266
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
Changes from all commits
dd8e4b5
e44d74a
433308c
775db02
94f04a9
6bfbb6c
b217c3f
6c71b67
dbe6f35
6291430
6339f65
da16bce
3eb471d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4441,8 +4441,8 @@ def test_set_get_ticklabels(): | |||||||||||||
# set ticklabel to 1 plot in normal way | ||||||||||||||
ax[0].set_xticks(range(10)) | ||||||||||||||
ax[0].set_yticks(range(10)) | ||||||||||||||
ax[0].set_xticklabels(['a', 'b', 'c', 'd']) | ||||||||||||||
ax[0].set_yticklabels(['11', '12', '13', '14']) | ||||||||||||||
ax[0].set_xticklabels(['a', 'b', 'c', 'd'] + 6 * ['']) | ||||||||||||||
ax[0].set_yticklabels(['11', '12', '13', '14'] + 6 * ['']) | ||||||||||||||
|
||||||||||||||
# set ticklabel to the other plot, expect the 2 plots have same label | ||||||||||||||
# setting pass get_ticklabels return value as ticklabels argument | ||||||||||||||
|
@@ -4452,6 +4452,26 @@ def test_set_get_ticklabels(): | |||||||||||||
ax[1].set_yticklabels(ax[0].get_yticklabels()) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def test_subsampled_ticklabels(): | ||||||||||||||
# test issue 11937 | ||||||||||||||
fig, ax = plt.subplots() | ||||||||||||||
ax.plot(np.arange(10)) | ||||||||||||||
ax.xaxis.set_ticks(np.arange(10) + 0.1) | ||||||||||||||
ax.locator_params(nbins=5) | ||||||||||||||
ax.xaxis.set_ticklabels([c for c in "bcdefghijk"]) | ||||||||||||||
Comment on lines
+4459
to
+4461
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting these together would make it a bit clearer:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the closest analogue to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't use twitter and haven't seen the tweet. I'm not saying the behavior is currently broken, just that it works in this case (I think--I haven't tried it) because the names are sorted in inverse order, and the "s" in "ticks" makes it sort before the first "l" in "ticklabels". It's an accident. It might be better to make it explicit by adding a "ticks" entry to Artist._prop_order to boost its priority. The _prop_order dict provides a way of setting priority at a higher level than the alphanumeric sort. Presently, it serves only to give 'color' low priority, so it is executed last. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The is the tweet that @story645 mentioned. For users, working by accident and working by design are the same thing. So I meant if this PR breaks it, that would not be good. However, it doesn't, so we're fine, even if it's working by accident right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'll take advantage of this to point to #16328 :) |
||||||||||||||
plt.draw() | ||||||||||||||
labels = [t.get_text() for t in ax.xaxis.get_ticklabels()] | ||||||||||||||
assert labels == ['b', 'd', 'f', 'h', 'j'] | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def test_mismatched_ticklabels(): | ||||||||||||||
fig, ax = plt.subplots() | ||||||||||||||
ax.plot(np.arange(10)) | ||||||||||||||
ax.xaxis.set_ticks([1.5, 2.5]) | ||||||||||||||
with pytest.raises(ValueError): | ||||||||||||||
ax.xaxis.set_ticklabels(['a', 'b', 'c']) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
@image_comparison(['retain_tick_visibility.png']) | ||||||||||||||
def test_retain_tick_visibility(): | ||||||||||||||
fig, ax = plt.subplots() | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L 1620 probably needs something like "Number of labels must be the same as number of ticks set by
set_ticks
or theFixedLocator
"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a reference to set_ticks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That helps, but I mean above in the Parameter description. Its a bit unclear as to what is meant by "tick labels". maybe: