Skip to content
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

Matplotlib cursor position wrong after using asfreq method to change freq of DateTimeIndex from None to something #5453

Closed
willfurnass opened this issue Nov 6, 2013 · 4 comments · Fixed by #7007
Labels
Bug Datetime Datetime data dtype Visualization plotting
Milestone

Comments

@willfurnass
Copy link
Contributor

After using the asfreq method to change the frequency of a time-series DataFrame from None to something e.g. 15Min the cursor position in matplotlib graphs of that DataFrame is no longer correct (usually shows a datetime just after the unix epoch). The following demonstrates this (NB dt in df1 is not a constant):

df1 = pandas.read_csv('tseries1.csv', names=['tstamp', 'Q'], parse_dates=True, 
    index_col='tstamp').clip_lower(0).fillna(0)
df1['T'] = pandas.read_csv('tseries2.csv', names=['tstamp', 'T'], parse_dates=True, 
    index_col='tstamp', squeeze=True).clip_lower(0).fillna(0)

df2 = df1.asfreq(freq='15Min', method='ffill')
# NB df1.index.freq is None
# NB df2.index.freq is <15 * Minutes>
df1.plot()
df2.plot()
plt.show()

I find the Matplotlib cursor position to be invaluable when looking for features in very long time-series.

Versions:

  • pandas master (commit ID 764b444)
  • numpy 1.8
  • matplotlib 1.3.0
@jreback
Copy link
Contributor

jreback commented Nov 6, 2013

can post a link or the file for csvs

or post a simple way to recreate them?

@willfurnass
Copy link
Contributor Author

Hi jreback. Here's a self-contained example:

import pandas
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt

tstamps = np.array([
       datetime(2011, 10,  1,  0,  0),
       datetime(2011, 10, 10,  0, 15),
       datetime(2011, 10, 20,  0, 30), 
       datetime(2012, 11,  6, 23, 15),
       datetime(2012, 11,  8, 23, 30),
       datetime(2012, 11,  9, 23, 45)])

df_orig = pandas.DataFrame(data={'col1':np.linspace(3, 30, 6)}, index=tstamps)
df_orig.plot()
df_new = df_orig.asfreq(freq='15Min', method='ffill')
df_new.plot()
plt.show()

@jreback
Copy link
Contributor

jreback commented Nov 6, 2013

gr8 thanks.....would welcom a PR for this.....!

@willfurnass
Copy link
Contributor Author

Crude workaround: edit _make_plot method in tools/plotting.py and clobber

if not self.x_compat and self.use_index and self._use_dynamic_x()

so that it always evaluates to False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants