Plotly express boxplot image export - part of box colors missing in svg file

hi MIkkel @mikkelc
Can you please share a minimal working example with us so we can replicate on our computer.

Also have you tried this Plotly link to see best ways of exporting images?

Hi, thanks for getting back to me.

Have checked the export image link, yes. I don’t see any use of it, unfortunately.

Here is an example:

import as px
import as pio
import pandas as pd
import plotly.graph_objs as go
import sys
import plotly

pio.templates.default = "simple_white"

x = ['Cat1', 'Cat1','Cat2', 'Cat2', 'Cat3', 'Cat3', 'Cat4', 'Cat4','Cat5', 'Cat5', 'Cat6', 'Cat6', 'Cat6', 'Cat7', 'Cat7',
     'Cat8', 'Cat8','Cat11', 'Cat11', 'Cat12','Cat12',     'Cat10', 'Cat10', 'Cat9', 'Cat9', 'Cat13', 'Cat13', 
     'Cat14', 'Cat14', 'Cat15', 'Cat15', 'Cat16','Cat16', 'Cat17']

y = [0.0, 0.0, 0.0, 0.0047, 0.0, 0.036, 0.0, 0.0, 0.12314, 0.02472495, 0.004,0.0, 0.013, 0.0, 0.0, 0.184, 0.056, 
     0.0186, 0.005928, 0.340, 0.20335, 0.0, 0.0, 0.2481, 0.12, 0.0, 0.0, 0.0201, 0.050, 0.0,0.0, 0.041, 0.0199, 0.0]

data = {
    "x": x,
    "y": y,

df = pd.DataFrame(data)

box_plot =, x="x", y="y", points="all", width=800, height=400)
box_plot.update_yaxes(title="Random numbers", title_font=dict(size=18, family='Arial'), tickfont=dict(family='Arial', size=18))
box_plot.update_xaxes(title=None, tickangle=45, title_font=dict(size=18, family='Arial'), tickfont=dict(family='Arial', size=18),
                          categoryorder='array', categoryarray=["Cat2", "Cat1", "Cat3","Cat4", "Cat5", "Cat6",
                                                               "Cat10", "Cat11", "Cat12","Cat9", "Cat8", "Cat7",
                                                               "Cat13", "Cat14", "Cat15","Cat16", "Cat17"])
box_plot.update_layout(margin=dict(l = 40, r = 10, t = 10, b = 25),
box_plot.update_traces(boxmean="sd", selector=dict(type='box'))
box_plot.update_traces(pointpos=-2, selector=dict(type='box'))
box_plot.update_traces(marker_symbol="circle-open", selector=dict(type='box'))

pio.write_image(box_plot, r"Boxplot_minimal_work_ex.svg")

I tested first with only two categories, and the export file looked fine! But when I increase the number of categories, it makes the bad quality graph. I wonder if there is an influence from setting the width - so I tried to delete the width and heigth setting from the expression but it gave same bad result.


I zoomed all boxes in Chrome, up to 400% and they look OK:

1 Like