plotting mangled with DatetimeIndex to ax with sharex and dissimilar indices #13341

Closed
tsdlovell opened this Issue Jun 1, 2016 · 3 comments

Comments

Projects
None yet
2 participants
Contributor

tsdlovell commented Jun 1, 2016

You can't see anything in the ax1 plot.

import pylab
import pandas as pd
pylab.ion(); pylab.show()
idx1 = pd.date_range('2015-01-01', periods=3, freq='1M')
idx2 = idx1[:1] + idx1[2:]
series1 = pd.Series(range(len(idx1)), idx1)
series2 = pd.Series(range(len(idx2)), idx2)


# this doesn't work
pylab.figure()
ax1 = pylab.subplot(211)
series1.plot(ax=ax1)
ax2 = pylab.subplot(212, sharex=ax1)
series2.plot(ax=ax2)

# this works
pylab.figure()
ax3 = pylab.subplot(211)
pylab.plot(series1.index, series1.values)
ax4 = pylab.subplot(212, sharex=ax3)
pylab.plot(series2.index, series2.values)

Issue seems to be with how its converting xdata

for ax in (ax1, ax2, ax3, ax4):
    print(ax.get_lines()[0].get_xdata())

[Period('2015-01', 'M') Period('2015-02', 'M') Period('2015-03', 'M')]
[datetime.datetime(2015, 1, 31, 0, 0) datetime.datetime(2015, 3, 31, 0, 0)]
['2015-01-31T00:00:00.000000000+0000' '2015-02-28T00:00:00.000000000+0000'
 '2015-03-31T00:00:00.000000000+0000']
['2015-01-31T00:00:00.000000000+0000' '2015-03-31T00:00:00.000000000+0000']

str(ax2.get_xticklabels()[0])
"Text(735636,0,'63273')"

str(ax4.get_xticklabels()[0])
"Text(735630,0,'Feb 01 2015')"
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.4.final.0
python-bits: 64
OS: Linux
OS-release: 3.14.32-pv-ts1
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.0
nose: None
pip: 8.1.1
setuptools: 20.7.0
Cython: 0.24
numpy: 1.10.4
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5.2
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.8.5
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
Contributor

tsdlovell commented Jun 1, 2016

Workaround: plot the shared axis' data to the new axis, clear the new axis, then plot the new data to the new axis

import pylab
import pandas as pd
pylab.ion(); pylab.show()
idx1 = pd.date_range('2015-01-01', periods=3, freq='1M')
idx2 = idx1[:1] + idx1[2:]
series1 = pd.Series(range(len(idx1)), idx1)
series2 = pd.Series(range(len(idx2)), idx2)

pylab.figure()
ax1 = pylab.subplot(211)
series1.plot(ax=ax1)
ax2 = pylab.subplot(212, sharex=ax1)
series1.plot(ax=ax2)
ax2.clear()
series2.plot(ax=ax2)

I can confirm this with 0.18.1.

import pandas as pd
import matplotlib.pyplot as plt

idx1 = pd.date_range('2015-01-01', periods=3, freq='1M')
idx2 = idx1[:1] + idx1[2:]
series1 = pd.Series(range(len(idx1)), idx1)
series2 = pd.Series(range(len(idx2)), idx2)

fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)
series1.plot(ax=ax1)
series2.plot(ax=ax2, x_compat=True)
plt.show()

The above kills the python process for me.

The reason is probably the combination of the regular and irregular (as you mention, they are processed differently: the first is converted to periods, the second not), but not sure why this kills the python process here.

Some related issues: pydata#6608, pydata#9053

Contributor

tsdlovell commented Jun 4, 2016

FYI: my workaround didn't work an a different dataset. Not sure what changed, but guessing something to do with xlimits of the data.

jorisvandenbossche added this to the 0.19.2 milestone Nov 26, 2016

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