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

Cursor x axis value is not shown when using regular timeseries #1670

Closed
lesteve opened this issue Jul 24, 2012 · 3 comments
Closed

Cursor x axis value is not shown when using regular timeseries #1670

lesteve opened this issue Jul 24, 2012 · 3 comments
Labels
Datetime Datetime data dtype Enhancement Visualization plotting
Milestone

Comments

@lesteve
Copy link
Contributor

lesteve commented Jul 24, 2012

Hi,

you should be able to paste the following snippet in a ipython --pylab session

import pandas
index = pandas.date_range(start='2001-1-1', end='2001-1-10', freq='D')
ts = pandas.TimeSeries(index=index, data=index.day)
figure()
ts.plot()
figure()
ts[:3].append(ts[6:]).plot()

Although the labelling is definitely nicer in the regular timeseries case, the cursor x axis value is not shown (bottom right corner with the tk pylab backend)
http://imgur.com/WCe6P,o8jge#0:

The irregular timeseries with the standard matlplotlib plot_date labelling does show a value for the cursor x axis value:
http://imgur.com/WCe6P,o8jge#1

I tried with the qt backend and I get the same results so it appears to be backend independent.

Not a huge deal but I find the cursor x axis value quite useful from time to time when interactively inspecting a plot (zooming, panning, etc...).

@lesteve
Copy link
Contributor Author

lesteve commented Jul 25, 2012

I see this has been tagged as Community, I'd be more than happy to take a look at this if I could get a few pointers to get started.

I actually started looking in matplotlib.axes.AxesSubplot.format_coord (let me know if this was the wrong place to start from) and ended up in pandas.tseries.converter.TimeSeries_DateFormatter.__call__ (ax.fmt_xdata is None in my case but that might be set to a function if we don't want to use the formatter in this case).

    def __call__(self, x, pos=0):
        if self.formatdict is None:
            return ''
        else:
            fmt = self.formatdict.pop(x, '')
            return Period(ordinal=int(x), freq=self.freq).strftime(fmt)

In my case the formatter formatdict is an empty dict so __call__ will always return an empty string. I am not sure I understand the reason for the pop (getting the string for a x coordinate may work only once) or the structure of the formatdict (do you really want one format string per timestamp), although I am guessing this is used in the scikits.timeseries style tick labelling.

Final question what is x supposed to be in this case, is it just an the underlying int64 value of the pandas.Timestamp? What's the best way to get it from a pandas.Timestamp object?

@willfurnass
Copy link
Contributor

A simple, possibly crude solution would be to use something like the following at the end of tsplot(series, plotf, **kwargs) in pandas/tseries/plotting.py

ax.format_coord = lambda t, y : "t = {:%Y-%m-%d %H-%M}    y = {}".format(\
                  datetime.fromtimestamp(t, series.index.to_timestamp().tz)), y)

wesm pushed a commit that referenced this issue Apr 10, 2013
Redefined the Matplotlib Axis.format_coord method in tseries.plotting.tsplot()

See Issue #1670

Conflicts:

	RELEASE.rst
	doc/source/v0.11.0.txt
@jreback
Copy link
Contributor

jreback commented Sep 21, 2013

merged in 0.11

@jreback jreback closed this as completed Sep 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Enhancement Visualization plotting
Projects
None yet
Development

No branches or pull requests

3 participants