Skip to content

Convert matplotlib stairs plots to plotly step lines - #5698

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

Convert matplotlib stairs plots to plotly step lines#5698
robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/fix-stairs-plot

Conversation

@robertoffmoura

Copy link
Copy Markdown
Contributor

mpl_to_plotly currently drops plt.stairs plots entirely. Matplotlib's stairs creates a StepPatch artist, which the exporter treats as a generic path, and the renderer only handles bar-chart paths, so the stairs plot is skipped with the warning "I found a path object that I don't think is part of a bar chart. Ignoring." The converted figure has zero traces.

Fix: draw_path now recognizes StepPatch artists and draws them as a line trace:

  • the StepPatch's path vertices already describe the horizontal/vertical step outline, so they're used directly (consecutive duplicates removed)
  • line styling (color, width, dash) comes from the patch's edge properties

Snippet 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)

fig, ax = plt.subplots()
ax.stairs(np.sin(x))
fig.savefig("stairs_mpl.png")

p = tls.mpl_to_plotly(fig)
p.write_image("stairs_plotly.png") 
matplotlib plotly before plotly after
stairs_mpl stairs_plotly stairs_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