Skip to content

No output of xticklabels when plotting to gridspec subplots #10162

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
JWarmenhoven opened this issue May 18, 2015 · 5 comments
Closed

No output of xticklabels when plotting to gridspec subplots #10162

JWarmenhoven opened this issue May 18, 2015 · 5 comments

Comments

@JWarmenhoven
Copy link

What seems to be the problem here?
The xticklabels for the first axes defined in a gridspec are not visible when plotting with pandas. The corresponding plot using pyplot.plot does have the labels.

pandas 0.16
matplotlib 1.4.3

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

%matplotlib inline
df = pd.DataFrame(np.random.randn(8, 4), index=np.arange(8), columns=['A', 'B', 'C', 'D'])

Matplotlib

gs = mpl.gridspec.GridSpec(2, 4)
ax1 = plt.subplot(gs[0,:-1])
ax2 = plt.subplot(gs[0,-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

ax1.plot(df.index.values, df.A)
ax2.plot(df.index.values, df.B)
ax3.plot(df.index.values, df.C)
ax4.plot(df.index.values, df.D)

gs.tight_layout(plt.gcf())

mpl

pandas

gs = mpl.gridspec.GridSpec(2, 4)
ax1 = plt.subplot(gs[0,:-1])
ax2 = plt.subplot(gs[0,-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

df.A.plot(ax=ax1)
df.B.plot(ax=ax2)
df.C.plot(ax=ax3)
df.D.plot(ax=ax4)

gs.tight_layout(plt.gcf())

pandas

It seems that xticklabels are absent when plotting with pandas to the first axis generated in a gridspec. Switching ax1 and ax2 definition:

pandas

gs = mpl.gridspec.GridSpec(2, 4)
ax2 = plt.subplot(gs[0,-1])
ax1 = plt.subplot(gs[0,:-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

df.A.plot(ax=ax1)
df.B.plot(ax=ax2)
df.C.plot(ax=ax3)
df.D.plot(ax=ax4)

gs.tight_layout(plt.gcf())

pandas2

Related?
http://stackoverflow.com/questions/29552382/legend-overriding-x-label-and-x-ticks

@TomAugspurger
Copy link
Contributor

Could you give it a shot on a newer version of pandas? All 3 are the same for me (master pandas, matplotlib 1.4.3)

@JWarmenhoven
Copy link
Author

Thanks! That seems to have solved the problem...

pandas 0.16.1
matplotlib 1.4.3

gs = mpl.gridspec.GridSpec(2, 4)
ax1 = plt.subplot(gs[0,:-1])
ax2 = plt.subplot(gs[0,-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

df.A.plot(ax=ax1)
df.B.plot(ax=ax2)
df.C.plot(ax=ax3)
df.D.plot(ax=ax4)

gs.tight_layout(plt.gcf())

pandas3

@jorisvandenbossche
Copy link
Member

Maybe we should add a test for this, to ensure this keeps working correctly in the future.
@JWarmenhoven Are you interested to do this?

@JWarmenhoven
Copy link
Author

Interested, yes. But since this is not my daily bread...it might take a while :-)
For starters, I wonder what bugfix in 0.16.1 solved this problem.
#9158 perhaps?

@jorisvandenbossche
Copy link
Member

That's possible.
If you have any questions how to get started with this, just ask! (here or on https://gitter.im/pydata/pandas)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants