FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Convert matplotlib stairs plots to plotly step lines by robertoffmoura · Pull Request #5698 · plotly/plotly.py · GitHub

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

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

Copy link
Copy Markdown

@robertoffmoura just a heads up that we saw your PRs come in. We're still planning to review them when we have a chance!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL