Fix boxplot conversion by mapping 'none' colors to transparent rgba - #5700
robertoffmoura wants to merge 1 commit into
Conversation
0313262 to
6e40185
Compare
6e40185 to
7306cb5
Compare
7306cb5 to
df0db87
Compare
camdecoster
left a comment
There was a problem hiding this comment.
Thanks for another update! I left some suggestions that I think would simplify/improve the code.
On another note, what do you think of updating our copy of mplexporter? It wouldn't be simple, but it might be worth the effort to take advantage of the updates that have been made in the last 12 years.
| color = mpltools.merge_color_and_opacity( | ||
| props["linestyle"]["color"], props["linestyle"]["alpha"] | ||
| ) |
There was a problem hiding this comment.
This will still throw if the line color has an alpha value, which can happen with mplexporter (because the returned color is rgba and merge_color_and_opacity calls hex_to_rgb). This is a preexisting bug, but you might as well address it since you're in this area.
There was a problem hiding this comment.
What do you think of combining merge_color_and_opacity and _export_color? They seem similar enough and you could deal with converting "none" internally rather than having to add a special case. Additionally, merge_color_and_opacity only gets called once, so we could remove that and replace it with the combined function.
There was a problem hiding this comment.
It looks like you could run into the same issue with "none" colors for text. That might be rare, but it could still happen. You can see this on L735 where color=props["style"]["color"] gets passed in without being run through _export_color. I'll let you decide if you make an update in this PR or a future one.
|
Could you also please add a changelog entry? |
mpl_to_plotly crashes when converting boxplots:
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: