Black Lives Matter. Please consider donating to Black Girls Code today.

Matplotlib drawstyle steps-pre

Hello,

I have some matplotlib plots that are converted and uploaded to plotly (by plotly.tools.mpl_to_plotly). It seems that the matplotlib drawstyle ‘steps-pre’ and ‘steps-post’ are not being converted to the plotly shape ‘hvh’ and ‘vhv’.

Does someone know how to achieve step plots in plotly, from my matplotlib figures?

Sample code:

from matplotlib import gridspec
import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import plotly.tools as tls
import plotly.plotly as plotpy

a = np.array([dt.datetime(2013, 1, 1), dt.datetime(2013, 1, 2), dt.datetime(2013, 1, 5), dt.datetime(2013, 1, 15), dt.datetime(2013, 1, 25)]) 
b = np.random.random_sample((5))
c = np.random.random_sample((5))

mpl_fig = plt.figure()
gs = gridspec.GridSpec(1, 1)
ax = mpl_fig.add_subplot(gs[0])
ax.grid(True)

p = []
plotargs = {'drawstyle':'steps-pre','linestyle':'--', 'marker':'o','color':'r'}
p.append(ax.plot_date(a, b, **plotargs))
plotargs = {'drawstyle':'steps-post','linestyle':'-', 'marker':'+','color':'b'}
p.append(ax.plot_date(a, c, **plotargs))
#plt.show()

plotly_fig = tls.mpl_to_plotly(mpl_fig)
plotly_fig['layout'].update(hovermode='closest')
plot_url = plotpy.plot(plotly_fig,filename='matplotlib step-plot',auto_open=False)