pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.8k stars 17.98k forks source link

Pandas does not respect shared axes in matplotlib #14074

Open danfrankj opened 8 years ago

danfrankj commented 8 years ago

Code Sample, a copy-pastable example if possible

x axis truncated by second call

ser1 = pd.Series({0:1, 1:2, 2:3})
ser2 = pd.Series({0:.5, 1:.1})

_, axes = plt.subplots(1, 2, sharex=True, sharey=True)

ser1.plot(ax=axes[0])
ser2.plot(ax=axes[1])

image

Expected Output

Using only matplotlib:

ser1 = pd.Series({0:1, 1:2, 2:3})
ser2 = pd.Series({0:.5, 1:.1})

_, axes = plt.subplots(1, 2, sharex=True, sharey=True)

axes[0].plot(ser1.index, ser1.values)
axes[1].plot(ser2.index, ser2.values)

image

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 14.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 25.1.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.1
sphinx: 1.3.5
patsy: 0.4.1
dateutil: 2.2
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: None
numexpr: 2.4.6
matplotlib: 1.5.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.14
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
TomAugspurger commented 8 years ago

I think the way to do this in pandas is

In [10]: df = pd.concat([ser1, ser2], axis=1)
In [11]: df.plot(sharex=True, sharey=True, subplots=True, layout=(1, 2))

We do quite a bit of messing axes when drawing, so supporting this could be a bit of work. Will leave open though, if you want to give it a shot.

danfrankj commented 8 years ago

@TomAugspurger My example is simplified - I actually do a fair bit of different computation for each subplot making it difficult/impossible to do within a single call to a DataFrame.plot

sinhrks commented 8 years ago

xaxis adjustment is performed on this line. it's nice to have a logic for shared xaxis.

thetestspecimen commented 7 months ago

Was going to look into this, but it doesn't seem to be an issue any more as far as I can tell.

Maybe this can be closed?