Skip to content

set_ticks() on shared axis #8320

@avdeevvadim

Description

@avdeevvadim

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions