Skip to content

Fix conversion of matplotlib polar plots - #4

Open
robertoffmoura wants to merge 6 commits into
mainfrom
rm/support-polar-plots
Open

robertoffmoura wants to merge 6 commits into
mainfrom
rm/support-polar-plots

Conversation

@robertoffmoura

@robertoffmoura robertoffmoura commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Originally opened as plotly/plotly.py#5771.

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
from matplotlylib import mpl_to_plotly

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 = 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

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