Skip to content

Fix conversion of matplotlib polar plots - #5771

Open
robertoffmoura wants to merge 5 commits into
plotly:mainfrom
robertoffmoura:rm/support-polar-plots
Open

robertoffmoura wants to merge 5 commits into
plotly:mainfrom
robertoffmoura:rm/support-polar-plots

Conversation

@robertoffmoura

Copy link
Copy Markdown
Contributor

mpl_to_plotly currently crashes for polar plots:

KeyError: 'bottom'

Fix:

  • polar axes are detected and converted to a plotly layout.polar subplot instead of cartesian axes
  • angular and radial tick values and labels are exported
  • polar background, grid, and frame colors are taken from matplotlib; the exporter runs tuple/RGBA colors through export_color, so custom frame and grid colors are picked up

Snippet to reproduce:

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

theta = np.linspace(0, 2 * np.pi, 400)

fig, ax = plt.subplots(subplot_kw={"projection": "polar"})
ax.plot(theta, 1 + 0.5 * np.sin(3 * theta), color="crimson", linewidth=2)
fig.savefig("polar_mpl.png")

p = tls.mpl_to_plotly(fig)   # raised KeyError: 'bottom' before
p.write_image("polar_plotly.png")
matplotlib plotly before plotly after
polar_mpl KeyError: 'bottom' polar_plotly

@camdecoster camdecoster self-assigned this Sep 23, 2026

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