Yaxis issue with time type data


#1

Hi, I’m facing an issue when using time data for grouped bars. Please find the issue summary and please share if you have any idea!
Plotly time yaxis doesn’t work rightly when using grouped bars with time formated data.
With one bar (fig2) when the time data is sorted the yaxis is right but when the data is not sorted (fig1) and add second bar (fig1+fig2) to the same plot the yaxis is mixed.
Any idea on this strange behaviour with time series data?

import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

x1 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
x2 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
d1 = pd.Series(['1.10.28','1.09.97','1.09.44','1.10.05',
           '1.11.21','1.09.63','1.09.90','1.10.28',
           '1.10.09','1.09.68','1.09.96','1.10.28',
           '1.10.75','1.11.43'])    #data is not sorted

d2 = pd.Series(['1.09.38','1.09.43','1.09.64','1.09.70',
           '1.09.93','1.10.04','1.10.32','1.10.43',
           '1.10.43','1.10.74','1.10.95','1.11.17',
           '1.11.27','1.12.55']) #data is sorted

y1 = pd.to_datetime(d1, format='%M.%S.%f').dt.time
y2 = pd.to_datetime(d2, format='%M.%S.%f').dt.time
trace1 = go.Bar(x=x1,y=y1)
trace2 = go.Bar(x=x2,y=y2)

layout = go.Layout(yaxis={'type': 'time','tickformat': '%M.%S.%f'})

fig1 = go.Figure(data = [trace1], layout=layout)
fig1.layout.title='fig1 - yaxis is ok'

fig2 = go.Figure(data = [trace2], layout=layout)
fig2.layout.title='fig2 - yaxis is ok'

fig3 = go.Figure(data = [trace1,trace2], layout=layout)
fig3 - yaxis is wrong'


#2

Your time strings aren’t formatted properly. Plotly thinks you’re plotting categories. You might want to look at https://help.plot.ly/date-format-and-time-series/


#3

Now I’m using datetime formatting. Yaxis labels seem fine although the bars don’t show up on the plot. If I’m using scatter or boxplot chart types then the data is visible but not for bar. What could be the issue?

import plotly.graph_objs as go
import pandas as pd
from datetime import datetime
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

d = pd.Series(['1.10.28','1.09.97','1.09.44','1.10.05',
           '1.11.21','1.09.63','1.09.90','1.10.28',
           '1.10.09','1.09.68','1.09.96','1.10.28',
           '1.10.75','1.11.43'])
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
y = pd.to_datetime(d, format='%M.%S.%f').dt.to_pydatetime()
trace1 = go.Scatter(x=x,y=y)
layout = go.Layout(yaxis={'type': 'time','tickformat': '%M.%S.%f'})
fig = go.Figure(data = [trace1], layout=layout)
iplot(fig)



#4

Ok. But from the code snippet you paster above, you’re not even plotting a bar trace (I don’t see any go.Bar statements).


#5

Yeah, the snippet includes scatter for proving that the data is fine for plotting, and if use:
trace1 = go.Bar(x=x, y=y)
then nothing is shown on the chart.
It seems to me that plotly is not able to deal with time type data when use bar chart…or my code is missing something?..


#6

Ok. Well this sounds more like a question for #api:python

I just notice that you have layout = go.Layout(yaxis={'type': 'time','tickformat': '%M.%S.%f'})

time isn’t a valid a axis type value, try type: 'date' instead.


#7

Ok. I have tried type:‘date’. Unfortunately, it doesn’t solve the issue.
I have noticed that the bar chart shows hover text (print screen below) with right values but no bars for that on the plot.