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

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

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Could you please add a changelog entry? Also, I've noticed that these tests don't run in CI. Do you know if that's intentional? It's not from a recent change that you made, but I'm curious if you know the history.

This branch has not been deployed

No deployments
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.

2 participants