Skip to content

Pandas rendering minor ticks in matplotlib sublots with shared axes #10657

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
mikepqr opened this issue Jul 22, 2015 · 9 comments · Fixed by #10879
Closed

Pandas rendering minor ticks in matplotlib sublots with shared axes #10657

mikepqr opened this issue Jul 22, 2015 · 9 comments · Fixed by #10879
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Milestone

Comments

@mikepqr
Copy link

mikepqr commented Jul 22, 2015

When the plot method of a dataframe is passed an ax keyword to render to a matplotlib subplot, the minor ticks and their labels are rendered regardless of whether sharex|y=True. The major ticks/labels are correctly removed.

Here's a short notebook that reproduces the issue. Note that the minor ticks are included in the upper axes of the final figure.

I am 90% certain this is a regression, but I wasn't able to pin down which version of pandas or matplotlib prompted this bug. Nor was I able to figure out whether this was due to pandas or matplotlib.

@mikepqr
Copy link
Author

mikepqr commented Jul 28, 2015

To add to this, the bug shown in the notebook linked above happens in

CPython 2.7.10
IPython 3.2.1
pandas 0.16.2
matplotlib 1.4.3

The bug does not happen with:

CPython 2.7.9
IPython 3.2.0
pandas 0.16.0
matplotlib 1.4.3

A pandas regression?

@TomAugspurger TomAugspurger added the Visualization plotting label Jul 28, 2015
@TomAugspurger
Copy link
Contributor

Thanks. It probably is a maybe a regression on our end. We kind of take over the axes and use our own logic for determining what to draw.

Your plot appears to work when you pass in sharex=True to the .plot calls. Could you try that out.

@mikepqr
Copy link
Author

mikepqr commented Jul 28, 2015

Yes, you're right. sharex=True in the individual .plot calls fixes this.

To be consistent with the matplotlib API this should not probably be necessary.

Happy to attempt a first PR if someone can point me in the direction of the file(s) that might have introduced this regression!

@TomAugspurger
Copy link
Contributor

@sinhrks am I correct in thinking that this is buggy?

In [25]: x = pd.DataFrame(list(zip(range(10), range(0, -10, -1))), columns=['a', 'b'])

In [26]: x.index = pd.date_range('2000-01-01', freq='Q', periods=10)

In [27]: fig, ax = plt.subplots(2, 1, sharex=True)

In [28]: x.plot(subplots=True, ax=ax)
Out[28]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x116b96630>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x117580198>], dtype=object)

In [29]: plt.savefig('nosavefig.png')

nosavefig
Note that the axis is not shared.

In [30]: fig, ax = plt.subplots(2, 1, sharex=True)

In [31]: x.plot(subplots=True, ax=ax, sharex=True)
/Users/tom.augspurger/Envs/py3/lib/python3.4/site-packages/pandas/tools/plotting.py:3218: UserWarning: When passing multiple axes, sharex and sharey are ignored.These settings must be specified when creating axes
  "These settings must be specified when creating axes", UserWarning)
Out[31]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x117deb940>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x10c64f828>], dtype=object)

In [32]: plt.savefig('with_share.png')

with_share
Now it is shared, but we get the warning telling us to do what we just did.

I haven't looked at this section in a while.

@mikepqr
Copy link
Author

mikepqr commented Jul 28, 2015

I think it's 015fc62 that's the problem.

Given the stated intentions of that commit, it's above my pay grade to determine whether this new behaviour is a feature or a bug!

@sinhrks
Copy link
Member

sinhrks commented Jul 30, 2015

@TomAugspurger Yes, major/minor ticklabel should be displayed when sharex=False (#7801), and hidden otherwise. Unfortunately test cases must have been incomplete.

@TomAugspurger TomAugspurger added the Regression Functionality that used to work in a prior pandas version label Jul 30, 2015
@TomAugspurger TomAugspurger modified the milestones: 0.17.0, Next Major Release Jul 30, 2015
@TomAugspurger
Copy link
Contributor

cc @JanSchulz

Do you remember in #9740 how the interaction of sharex in plt.subplots and sharex in df.plot is supposed to work?

@jankatins
Copy link
Contributor

@TomAugspurger sorry, no idea whats going wrong here. I only tested (optimized for...) a gridspec without sharex, seems that I overlooked this case :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants