question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plotting DataFrame with timedelta64 (y-axis)

See original GitHub issue

Similar to #799 but on y-axis and https://github.com/pandas-dev/pandas/issues/16953

import pandas as pd
from pandas.compat import StringIO
import plotly
import plotly.graph_objs as go


dat = """c1,c2,c3
1000,2000,1500
9000,8000,1600"""

df = pd.read_csv(StringIO(dat))

df = df.apply(lambda x: pd.to_timedelta(x, unit='ms'))

print(df)
print(df.dtypes)
print(df.index)

trace1 = go.Bar(
    x=df.index,
    y=df.c1,
    name='c1'
)
trace2 = go.Bar(
    x=df.index,
    y=df.c2,
    name='c2'
)

trace3 = go.Bar(
    x=df.index,
    y=df.c3,
    name='c3'
)

data = [trace1, trace2, trace3]
layout = go.Layout(
    barmode='group'
)

plotly.offline.plot({
"data": data,
"layout": layout
})

displays

capture d ecran 2017-07-22 a 12 35 57

y-axis values are not correctly displayed

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
jaladh-singhalcommented, Feb 27, 2020

Is there any progress regarding this, I really need to use timedelta64 on Y-axis?

0reactions
ThomasGlcommented, May 5, 2022

Hey, it’s a bit late to the party. But, I wrote a solution for this issue. You can have dash, including its iterative features working and a datetime format in any sense. This, includes the autorender to solve for many x_sample points, so that it won’t crash your axis.

Such is the following:

For the x_axis make absolutely sure that the format of your list is list[str] and they are consistent. ALSO, match the format in those strings in the tickformat of your list, the reference for time is standard as used in datetime objects, for future reference check: https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-tickformat

e.g.:

mock_list = ["00:00:00", "00:00:01"]

mock_list to be the x values in a scatter plot for instance then adjust the axis as follows:

fig.update_xaxes( tickformat="%H:%M:%S")

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matplotlib timedelta64 index as x-axis - Stack Overflow
First of all you may use pandas directly to plot the data. I.e. instead of plt.plot(df) you can use df.plot().
Read more >
How to change xticklables from pandas plot with timedelta x ...
I am trying to plot this dataframe: import numpy as np import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({'d': [np.timedelta64(5,'h'), ......
Read more >
How to handle time series data with ease - Pandas
Using pandas datetime properties#. I want to work with the dates in the column datetime as datetime objects instead of plain text. > ......
Read more >
Visualization with Seaborn | Python Data Science Handbook
In order to visualize data from a Pandas DataFrame , you must extract each Series and ... Here is an example of a...
Read more >
Timeseries plot with timedelta axis - Plotly Community Forum
Below is my simple code. I want the x axis ticks to be in %M:%S format. Thanks import pandas as pd import plotly.graph_objs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found