Skip to content

Fix boxplot conversion by mapping 'none' colors to transparent rgba - #5700

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

Fix boxplot conversion by mapping 'none' colors to transparent rgba#5700
robertoffmoura wants to merge 1 commit into
plotly:mainfrom
robertoffmoura:rm/fix-boxplot

Conversation

@robertoffmoura

Copy link
Copy Markdown
Contributor

mpl_to_plotly crashes when converting boxplots:

ValueError: Invalid value of type 'builtins.str' received for the 'color' property of scatter.marker
    Received value: 'none'

Boxplot outlier markers use facecolor="none" (fully transparent) in matplotlib. The converter passes that color verbatim into the plotly trace, and plotly.py's validators reject "none" for color property.

Fix: transparent matplotlib colors are mapped to rgba(0,0,0,0), which plotly accepts.

Snippet to reproduce:

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

fig, ax = plt.subplots()
ax.boxplot(np.random.randn(100, 4))
fig.savefig("boxplot_mpl.png")

p = tls.mpl_to_plotly(fig)   # raised ValueError before the fix
p.write_image("boxplot_plotly.png")

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