✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Possible bug color_discrete_map and opacity in px.pie (plotly.io as pio)

I’m using pio.show(pie_fig) to plot my pie_fig. My version of plotly is 4.5.0. but color_discrete_map and opacity are not working when I use the documentation examples here:

df = px.data.tips()
fig = px.pie(df, values='tip', names='day', color='day',
             color_discrete_map={'Thur':'lightcyan',
                                 'Fri':'cyan',
                                 'Sat':'royalblue',
                                 'Sun':'darkblue'})
pio.show(fig)

The colors don’t change. I get the default colors. And in…

df = px.data.tips()
fig = px.pie(df, values='tip', names='day', opacity=0.4, color_discrete_sequence=px.colors.sequential.RdBu)
pio.show(fig)

opacity raises this error:

ValueError: Invalid property specified for object of type plotly.graph_objs.pie.Marker: ‘opacity’
Valid properties:
colors…
colorssrc…
line…

Is this a bug or am I going crazy?

Hi @adamschroeder

With Plotly 4.5.4 the color_discrete_map works:

Fig1

but opacity is still an Invalid property. You should open an issue.

1 Like

Sorry about this! That argument should not be there, as indeed marker opacity is not supported in the underlying rendering system… Should be fixed in the next version: https://github.com/plotly/plotly.py/pull/2294

1 Like

@nicolaskruchten I have no experience with plotly express I just pasted the code above in my notebook. After running, it was displayed that opacity is an invalid property. Then I typed help(px.pie) and opacity was listed as a pie attribute.
That’s why I suggested to open an issue. I’m sorry!!!

@empet there’s nothing to apologize for! There is indeed a bug here: the opacity argument in px.pie should not be there and recommending to open an issue is the right thing to do :slight_smile:

In this case I saw this post and opened a pull request immediately to save time but I don’t read as many forum posts as I would like so the “open an issue” plan is always a safe bet!

Thanks!