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

Timeseries plots #22

Closed
glentner opened this issue Mar 3, 2022 · 5 comments
Closed

Timeseries plots #22

glentner opened this issue Mar 3, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@glentner
Copy link

glentner commented Mar 3, 2022

I've been playing with tplot for a few days now building a command-line tool to show some usage data, basically I've created a CLI connecting pandas.read_csv to tplot. This has turned out really well and the plots look great in the terminal.

Any thoughts on the best way to handle timeseries/datetime on the x-axis? One approach might be for the user to just cast the timestamps to Unix epoch times, but that's not very human readable on the axis labels. Do you have any sense of how much of a challenge it would be to construct a label formatter on the x-axis to show dates and times nicely (like months+days, or hours+minutes)?

Just sharing ideas, thanks.

@glentner
Copy link
Author

glentner commented Mar 3, 2022

Right now I'm just forcing parsed date times to unix epochs in seconds and let you scale by day/hour/min in either direction as an offset. This isn't ideal though, it would be awesome to have x-axis labels properly deal in dates, etc.

Screen Shot 2022-03-03 at 4 46 34 PM

@JeroenDelcour
Copy link
Owner

That's definitely a good suggestion! Shouldn't be too difficult to handle Datetime objects properly (scaling using epoch time and labeling with human-readable text). I'll try to have a look at it in the next week or so.

Also: wonderful to see tplot being used for cool stuff, that figure looks great!

@JeroenDelcour JeroenDelcour self-assigned this Mar 5, 2022
@JeroenDelcour JeroenDelcour added the enhancement New feature or request label Mar 5, 2022
@glentner
Copy link
Author

glentner commented Mar 8, 2022

Progress continues on a better interface. I think with good time series labeling this could look really great.

Screen Shot 2022-03-08 at 6 29 49 PM

Screen Shot 2022-03-08 at 6 34 35 PM

Screen Shot 2022-03-08 at 6 55 31 PM

@JeroenDelcour
Copy link
Owner

Handling datetime objects is more difficult than I thought. I figured I could just use epoch timestamps to plot everything as numbers and show the datetime as a string for the axis tick labels, but that beaks the assumption that tick labels and their values are the same - something that is pretty fundamental to how tplot is set up.

There's also the issue of the interval between ticks. tplot creates ticks at round(ish) intervals like 1, 2, 5, 10, 20, 50, 100, etc. This doesn't work for a lot of situations with datetimes: tplot might decide on a 100 000 second tick interval, which is a nice round number in seconds (and epoch timestamps are in seconds), but measured in days that's roughly 1.1574074 - yuck! Depending on what timescale you're plotting, tick intervals end up looking arbitrary. And then there's units of time that have a variable length, such as months or years (leap days). Time is complicated.

Maybe there are existing open source implementations for getting an appropriate time interval given a set of dates and times, and solutions for any other peculiarities that come up. But unless there's significant interest from a lot of people, I don't think it's worth trying to support datetime objects. It could potentially add a lot of complexity, and I'd like to keep tplot simple.

Your current solution of converting datetimes to a manually chosen time interval (e.g. number of days) seems like the best approach. If you really need to handle datetime objects with all the complexity they bring, there are enough feature-rich plotting libraries out there that can do pretty much whatever you want, including plotting date intervals nine ways to Sunday.

Sorry to get your hopes up!

@impredicative
Copy link

impredicative commented Oct 9, 2023

I am instead using the largest differentiating unit as this grants me better human-readability, at least in some circumstances, without having to resort to relative values. This function converts datetimes to a dynamic range of numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants