Skip to content

Convert matplotlib step drawstyles to plotly line shapes - #5697

Open
robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/fix-step-plot
Open

Convert matplotlib step drawstyles to plotly line shapes#5697
robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/fix-step-plot

Conversation

@robertoffmoura

@robertoffmoura robertoffmoura commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

mpl_to_plotly converts plt.step plots (and any drawstyle="steps-*" line) as ordinary straight lines, connecting the points with diagonals instead of the vertical/horizontal step segments matplotlib draws.

Before: the converted trace has line.shape = None, so plotly draws diagonal connections between consecutive points.

After: the drawstyle is mapped to plotly's step shapes, matching matplotlib's geometry exactly:

matplotlib drawstyle plotly line.shape
steps-pre (and plt.step, steps) vh
steps-post hv
steps-mid hvh

Steps to reproduce:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import plotly.tools as tls

x = np.linspace(0, 10, 20)
y = np.sin(x)

fig, ax = plt.subplots()
ax.step(x, y)
fig.savefig("step_mpl.png")

p = tls.mpl_to_plotly(fig)
p.write_image("step_plotly.png")

print(p.data[0].line.shape)   # "vh" with the fix; None before
matplotlib plotly before plotly after
step_mpl step_plotly_before step_plotly_after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant