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

Plot PeriodIndex data with steps #11862

Closed
egpbos opened this issue Dec 18, 2015 · 4 comments
Closed

Plot PeriodIndex data with steps #11862

egpbos opened this issue Dec 18, 2015 · 4 comments
Labels
Enhancement Period Period data type Visualization plotting

Comments

@egpbos
Copy link

egpbos commented Dec 18, 2015

I would find it more natural for PeriodIndexed data to be plotted by default as a stepped line. A step better conveys the fact that the y-value one is plotting corresponds to that entire x-region, whereas a (linearly or otherwise) interpolated line suggests that one is using Timestamped data (since it suggests that the y-value is different at each point in time, which for periods is impossible to know).

It is, of course, possible to do this manually with drawstyle=steps, but this has the annoying problem that one of the Period "bins" will be missing (the one at the end). steps-mid is ugly, since it cuts off half of the steps at both edges.

It would be nice if the default would be changed to this drawstyle, but it would be even better if this style would be extended some way to fully handle Periods. Ideally, each Period step would be plotted between the edges of the Period and irregular Periods would be supported as well.

@TomAugspurger
Copy link
Contributor

My initial thoughts are that this wouldn't be worth making an API breaking change, so I don't see the default changing to a different linestyle.

but it would be even better if this style would be extended some way to fully handle Periods

Not quite sure what you're saying here, sorry. But I think that sounds like more of an enhancement for matplotlib? As long as pandas gets the data to matplotlib in some format that it understands.

FWIW, I would typically use something like style=k. to avoid the suggestion that the y-value is changing linearly within/between periods.

@egpbos
Copy link
Author

egpbos commented Jan 12, 2016

Let me explain a bit further. I would say that using steps is maximally informative given Period data. For instance, say you have a table with a monthly period index. If January 2016 has value 2.4, then at all horizontal locations inside the January period, i.e. January 1st 2016 at 11 pm, January 22nd 2016 at 4 am, etc., we should plot the value 2.4. I think this is the most complete and correct way of plotting such Period data. If you only plot a dot in the middle of the Period, say at Jan 16th 0:00, then that expresses that you only know the value at that point, while in fact you know it at all other points in the Period as well.

Matplotlib is only a plotting library/backend. As far as I understand, it doesn't know (and doesn't want to know) about data or types of data, only about canvases and coordinates, lines, shapes etc. on those canvases.

I can understand that you don't want to break the API. I guess that in any case plotting is not the core business of Pandas. Perhaps, in the long run, it would be nice to build a completely separate package that focuses purely on interfacing DataFrames, in all their variety, with Matplotlib.

@TomAugspurger
Copy link
Contributor

All fair points. #8707 is adding a new Index type for representing intervals. I think the current plan is to rewrite Period to be backed by InntervalIndex. We need to think about what plotting those will look like (by default), so we'll keep this issue in mind when working on that.

@mroeschke mroeschke added Enhancement Period Period data type and removed API Design labels Apr 21, 2021
@mroeschke
Copy link
Member

Thanks for the issue, but it appears this hasn't gotten traction in a while so closing

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

No branches or pull requests

3 participants