How to overlay multiple customized pie charts?


I’m trying to reproduce in Plotly a chart that I made using matplotlib since I would like to make it interactive and potentially make use of other features that Plotly has to offer.

I have a couple of questions:

  1. Is there a way to adjust the radius for each slice separately? I know this is possible in Matplotlib but I haven’t found a way to do the same in Plotly.
  2. Is there a proper way to overlay multiple charts, basically placing one chart over another but of different sizes? In the code example below I’ve attempted to do so but haven’t quite got the hang of it.
  3. Also, is there any way to use a continuous colormap/scale applied to a piechart? So far I’ve only seen the option of using discrete. Pie documentation
  4. Is it possible to turn a slice/wedge invisible but without changing positions? I’ve seen this example but I would like that the piechart doesn’t change its shape, I would like the location of the invisible slice to be left as it is. I found some example but it’s not what I want: Is there a way to hide some slices by default in a pie chart?
import plotly.graph_objs as go

df = pd.read_csv('animation/data/factors_df_2022-03-09_06-00-06-30.csv', index_col=0)
# change index to string
df.index =
names = ['Null', 'Pred=-1', 'Pred=0', 'Other', 'R_min'] + df.index[5:].tolist()

trace0 = go.Pie(
    values=df['sum_cnt'], labels=names, opacity=0.5)

trace1 = go.Pie(
    values=df['sum_cnt'], marker_colors=px.colors.sequential.Sunset, 
    domain={'x': [0.33, 0.66], 'y': [0.0, 0.6]})

data = [trace0,trace1]

layout = go.Layout(title="FPP chart",

fig = go.Figure(data=data, layout=layout, layout_showlegend=False)


I’m not fixated on using a piechart if there are other ways however, essentially what I did in matplotlib was using Pie class.

Hi @geosphere ! Could you share what are you trying to communicate with the graph? Have you considered sunburst charts?

Hi @celia . Sure, I’ll try my best to put it into words.

I’m using the graph to represent some calculated fields at a certain timeframe and for that I used a pie chart in matplotlib where I managed to customize it in such a way that I am conveying 3 dimensions/columns using 3 properties of the pie chart.

  • one is represented as the size of the slice of a pie (sum of the activity for each category)
  • second dimension is represented by the radius of the graph, floating values
  • third dimension is represented by the color, using a continuous colorbar (Also added a legend)

I’m also using a couple of circles of different line styles to represent the second dimension, basically a min, average, and maximum of that column.

Lastly, I’m also using a bar chart to represent the total activity, the sum of all categories (column/variable that I represented through slices of the pie) placed slightly below and on top of the pie chart with adjusted opacity.
The same visualization is used in an animation where all three dimensions are changing depending on the values of the field.

Btw, I tried to use a sunburst but the thing is my data is not hierarchical so adapting it to my needs is rather tricky.

Here I tried to make use of pull parameter in pie chart to mimic the radius so I based a normalized list to it with the values from my dataframe and I got something like this but that leaves a big gap in the middle so I tried to somehow hide it with another pie placed on top but it’s quite far from what I would want.