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

Closed
williamsmj opened this Issue Jul 22, 2015 · 9 comments

Comments

Projects
None yet
5 participants

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.

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?

Contributor

TomAugspurger commented Jul 28, 2015

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.

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!

Contributor

TomAugspurger commented Jul 28, 2015

@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.

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!

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.

Contributor

TomAugspurger commented Jul 30, 2015

cc @janschulz

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

Contributor

janschulz commented Jul 30, 2015

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

@jreback jreback modified the milestone: 0.17.0, Next Major Release Aug 21, 2015

jreback closed this in #10879 Sep 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment