Thanks to visit codestin.com
Credit goes to github.com

Skip to content

set_ticks() on shared axis #8320

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

Closed
avdeevvadim opened this issue Mar 17, 2017 · 5 comments
Closed

set_ticks() on shared axis #8320

avdeevvadim opened this issue Mar 17, 2017 · 5 comments
Labels
status: inactive Marked by the “Stale” Github Action
Milestone

Comments

@avdeevvadim
Copy link

Bug report

Bug summary

Not sure it's a bug, but in the following example the order in which you change subplots properties matters.
Suppose you have several subplots with the shared axis and you set ticks for this axis with the range outside the data. Doing it for all subplots one by one, you get ticks placed correctly on the last subplot and incorrectly on all others.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots(3, 1, sharex=True)

ax[0].scatter([0, 1], [0, 1])
ax[0].set_xticks([0, 1, 2])

ax[1].scatter([0, 1], [0, 1])
ax[1].set_xticks([0, 1, 2])

ax[2].scatter([0, 1], [0, 1])
ax[2].set_xticks([0, 1, 2])

plt.show()

Actual outcome
matplotlib_wrong

Expected outcome

Let's try the same code, but change all subplots properties afterwards.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(3, 1, sharex=True)

ax[0].scatter([0, 1], [0, 1])

ax[1].scatter([0, 1], [0, 1])

ax[2].scatter([0, 1], [0, 1])

plt.setp(ax, xticks=[0, 1, 2])

"""
Alternatively,
ax[0].set_xticks([0, 1, 2])
ax[1].set_xticks([0, 1, 2])
ax[2].set_xticks([0, 1, 2])
"""

plt.show()

Result:
matplotlib_right

Not so expected outcome

Finally, change all subplots properties somewhere earlier.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(3, 1, sharex=True)

ax[0].scatter([0, 1], [0, 1])

plt.setp(ax, xticks=[0, 1, 2])

ax[1].scatter([0, 1], [0, 1])

ax[2].scatter([0, 1], [0, 1])

plt.show()

Result:
matplotlib_not_expected

Matplotlib version
Matplotlib 2.0.0 (installed using Anaconda)
Python 3.5.3
Fedora 25

@afvincent afvincent added this to the v2.2 milestone Oct 23, 2017
@HHest
Copy link
Contributor

HHest commented Oct 17, 2018

When one performs set_xticks on one Axes object, the others should follow since sharex=True.
If this rule is respected, then the sequencing issue would go away, I think.

In other words:

    fig, ax = plt.subplots(3, 1, sharex=True)
    ax[0].scatter([0, 1], [0, 1])
    ax[1].scatter([0, 1], [0, 1])
    ax[2].scatter([0, 1], [0, 1])
    ax[0].set_xticks([0, 1, 2])
    plt.show()

should produce:
image

Currently it is producing:
image

@csbrown
Copy link

csbrown commented Feb 5, 2020

Is there a workaround for this?

@ImportanceOfBeingErnest
Copy link
Member

@csbrown Yes, the workaround is found under the headline "Expected outcome" in the original post.

@github-actions
Copy link

github-actions bot commented Apr 9, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 9, 2023
@QuLogic
Copy link
Member

QuLogic commented Apr 12, 2023

This was fixed by #18529.

@QuLogic QuLogic closed this as completed Apr 12, 2023
@QuLogic QuLogic modified the milestones: future releases, v3.4.0 Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

6 participants