Plotly.py: Plotting DataFrame with timedelta64 (y-axis)

Created on 22 Jul 2017  路  2Comments  路  Source: plotly/plotly.py

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

enhancement

Most helpful comment

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

All 2 comments

A workaround is to do:

for col in df.columns:
    df[col] = df[col] + pd.to_datetime('1970/01/01')

capture d ecran 2017-07-22 a 12 42 25

but it will be nice if plotly.py could handle timedelta64 on y-axis

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlizanae picture vlizanae  路  4Comments

tssweeney picture tssweeney  路  4Comments

entron picture entron  路  4Comments

keithjjones picture keithjjones  路  3Comments

dhirschfeld picture dhirschfeld  路  4Comments