Axes format/sorting bug

I’m trying to plot a dual Y axis plot with a mm:ss on the Y1 axis.

As you can see in the graph, plotly isn’t sorting the hh:mm:ss values correctly.

If i leave the data as “seconds”, it will display fine.

If I convert seconds to a python timedelta and put into the list as a str and format as a date on the axis, I get this bizarre result. 1:49 gets sorted as the lowest value instead of where it belongs.

I’m looking for a way to have seconds display as mm:ss on a y access via the python API.

Hi @jsm,

Plotly.py doesn’t have specific support for the timedelta type. I think you could use a datetime array and then format the ticks to only display hh:mm:ss (using the yaxis.tickformat property).

Feel free to add a reproducible example if you’d like help working through the details,

-Jon

Jon,

Thanks! That did the trick. White iterating over the values in the CSV, I just used this:

Pace.append(datetime.datetime.fromtimestamp(1514764800+int(row['Current_Pace'])))
Time.append(datetime.datetime.fromtimestamp(1514764800+float(row['Time'])))

and formatted the axis with:

yaxis=dict(
    title='Split',
    tickformat='%M:%S',
    range=[min(Pace)-datetime.timedelta(seconds=20), max(Pace) + datetime.timedelta(seconds=20)]
),

and everything worked as expected.

1 Like