GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Render matplotlib path collections (violin plots, pcolor, stems, etc.) in plotly by robertoffmoura · Pull Request #5702 · plotly/plotly.py

Conversation

@robertoffmoura

@robertoffmoura robertoffmoura commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

mpl_to_plotly silently drops several common plot types. Violin plots, pcolor, event plots, stack plots, fill_between and stem plots all produce PolyCollection/LineCollection artists in data coordinates, which the renderer skipped with "Dang! That path collection is out of this world...". The converted figure ends up with zero traces (except for stem, which gets partially drawn).

Fix: data-coordinate path collections are now drawn:

  • collections with face colors (violin bodies, pcolor cells, stacked areas, fills) → filled polygons (fill="toself")
  • collections without face colors (contour lines, stem lines) → plain line traces
  • per-path colors/widths handled for collections that mix them; empty color arrays and degenerate paths skipped

Before: plots converts to 0 traces (empty figures).
After: plots render correctly.

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(-3, 3, 30)
X, Y = np.meshgrid(x, x)
t = np.linspace(0, 2 * np.pi, 50)

cases = {
    "violinplot":   lambda: plt.violinplot(np.random.randn(100, 3)),
    "pcolor":       lambda: plt.pcolor(X, Y, np.sin(X) * np.cos(Y)),
    "eventplot":    lambda: plt.eventplot([np.random.randn(20) for _ in range(5)]),
    "stackplot":    lambda: plt.stackplot(np.arange(10), np.random.rand(10), np.random.rand(10), np.random.rand(10)),
    "fill_between": lambda: plt.fill_between(t, np.sin(t), np.cos(t)),
    "stem":         lambda: plt.stem(np.linspace(0, 2 * np.pi, 20), np.sin(np.linspace(0, 2 * np.pi, 20))),
}

for name, build in cases.items():
    fig, ax = plt.subplots()
    build()
    fig.savefig(f"{name}_mpl.png")

    p = tls.mpl_to_plotly(fig)   # 0 traces for all of these before the fix (except stem, which had some traces)
    p.write_image(f"{name}_plotly.png")

    print(f"{name:13s} -> {len(p.data)} traces")
Plot type Converted plotly figure
violinplot (12 traces) violinplot_plotly
pcolor (900 traces) pcolor_plotly
eventplot (100 traces) eventplot_plotly
stackplot (3 traces) stackplot_plotly
fill_between (1 trace) fill_between_plotly
stem (22 traces) stem_plotly

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@robertoffmoura
Draw data-coordinate path collections as filled polygons
513e432
@robertclaus
robertclaus requested a review from camdecoster August 13, 2026 19:50
@robertclaus robertclaus assigned camdecoster Aug 13, 2026
camdecoster
camdecoster requested changes Aug 21, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the PR! Overall this is in good shape but needs a couple of changes. Could you also please add a changelog entry?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plotly/matplotlylib/renderer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

robertoffmoura added 6 commits August 21, 2026 09:48
@robertoffmoura
Run ruff format
f0c56c0
@robertoffmoura
Remove opacity field from _draw_filled_path_collection
738e81d
@robertoffmoura
Replace colors[min(i, n - 1)] with colors[i % n]
74fac13
@robertoffmoura
Remove unreachable non-string fallback from _export_color
755875c
@robertoffmoura
Convert date x-values for filled path collections
a71efd8
@robertoffmoura
Add changelog entry for path collection rendering fix
c694e22
@robertoffmoura

robertoffmoura commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I addressed your comments and added a changelog entry.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertoffmoura
robertoffmoura requested a review from camdecoster August 21, 2026 14:29
@camdecoster
Update changelog entry
2eded50
camdecoster
camdecoster previously approved these changes Aug 21, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the fix!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
Merge branch 'main' into rm/fix-violin-plot
a8fac51
@camdecoster
camdecoster dismissed their stale review via a8fac51 August 21, 2026 16:21
camdecoster
camdecoster approved these changes Aug 21, 2026
View reviewed changes
@camdecoster
camdecoster merged commit a5974ce into plotly:main Aug 21, 2026
24 checks passed

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@camdecoster camdecoster

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@robertoffmoura @camdecoster
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.