Plotting DataFrame with timedelta64 (y-axis)
See original GitHub issueSimilar 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
y-axis values are not correctly displayed
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any progress regarding this, I really need to use timedelta64 on Y-axis?
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")