Skip to content

Relative date on x-axis #1744

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

Closed
Romainpetit opened this issue May 30, 2017 · 4 comments
Closed

Relative date on x-axis #1744

Romainpetit opened this issue May 30, 2017 · 4 comments

Comments

@Romainpetit
Copy link

Romainpetit commented May 30, 2017

Problem
I'm using plotly to display timed data, but here the exact date is of no importance, only the relative time between the values is. I'm wondering if there is any existing setting about this.

For the moment, I get this result with tickmode: 'auto', type: 'date'
image
image

Wish
I'd like to set my first point as the zero, and then have all other times relative to it.
The tick would display the time relatively to this first date :
image
image

Since I'll be displaying various data of different time scales, tickformat is of little help. I'd need an automatic date formatter with customizable format settings.

This is related to this debate on the pertinence of this automatic date format: #99

Any help appreciated!

@etpinard
Copy link
Contributor

etpinard commented May 30, 2017

That's an interesting proposition. I've never came across a special relative time format in other graphing library. @Romainpetit Does that exist anywhere else?

In your case (in JS at least), it would be pretty easy to convert your x coordinates to milliseconds (i.e with new Date().getTime()) from that base time step and pass that to Plotly.plot.

@Romainpetit
Copy link
Author

I don't know a graphing library that offers such a relative time in its options @etpinard.
This specific point is manageable tough: I can process my data in milliseconds by substracting the first point's timestamp to all points values, like you said.

Now with this relative timing in ms,

  • In plotly, I can display it telling xaxis to use type: 'linear': that will display it as a quantity unit. I can have the s unit display with ticksuffix: "s" and try to have some formatting for large number with tickformat. But still, we're only showing seconds.
  • In an environment where I have more control, I can use a JS time formatting library like moment.js or dateformat.js to render this time in ms to time-formatted data: ms, s, h, day ...

Other option seems to be to dig in the formatTime(), ms2DateTimeLocal() or formatTime() functions in plotly's dates.js file, to get a well-formatted time output that fits my needs.

@etpinard
Copy link
Contributor

etpinard commented Jun 1, 2017

In plotly, I can display it telling xaxis to use type: 'linear': that will display it as a quantity unit. I can have the s unit display with ticksuffix: "s" and try to have some formatting for large number with tickformat. But still, we're only showing seconds.

You can also try tickvals / ticktext to customize your axis labels (see example https://codepen.io/etpinard/pen/YWEdJX?editors=0010). This solution might not behave as desired on zoom, but it should get you close to what you want.

@etpinard
Copy link
Contributor

etpinard commented Jun 5, 2017

This ticket won't directly result in a PR, so I'll close it.

Thanks for writing in @Romainpetit

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

No branches or pull requests

2 participants