How to create subplots with pie charts?

Hello,
I would like to display two pie charts on the same level (row). I tried to use the following libraries

Blockquote

import plotly.graph_objects as go
from plotly.subplots import make_subplots

But without any successes… I keep receiving errors messages as I try to use the following pattern :

Blockquote

Create subplots: use ‘domain’ type for Pie subplot

fig = make_subplots(rows=1, cols=2, specs=[[{‘type’:‘domain’}, {‘type’:‘domain’}]])

fig.add_trace(go.Pie(labels=labels, values=‘Quantité de films ayant pour genre principal’, name='genre),
1, 1)
fig.add_trace(go.Pie(labels=labels, values=‘Quantité de films ayant pour genre secondaire’, name='genre),
1, 2)

Use hole to create a donut-like pie chart

fig.update_traces(hole=.4, hoverinfo=“label+percent+name”)

fig.update_layout(
title_text=“Text”,
# Add annotations in the center of the donut pies.
annotations=[dict(text=‘mytext’, x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text=‘mytext2’, x=0.82, y=0.5, font_size=20, showarrow=False)])
fig.show()

Here’s a copy of the dataframe I used and the two consecutive pie charts I managed to get as single plots.

hello again,

I managed to obtain the result I was expecting.

First I changed my dataframe columns into numpy arrays :

values1 = df_full_genres2[‘Quantité de films ayant pour genre principal’].to_numpy()
print(values1)
values2 = df_full_genres2[‘Quantité de films ayant pour genre secondaire’].to_numpy()
print(values2)
genre1 = df_full_genres2[‘genre’].to_numpy()
print(genre1)

image

Then I used this :

fig = make_subplots(rows=1, cols=2, specs=[[{“type”: “pie”}, {“type”: “pie”}]], subplot_titles = (‘Proportion de films par rapport au genre principal’, ‘Proportion de films par rapport au genre secondaire’))
fig.add_trace(go.Pie(
values = values1,
labels = genre1,
domain = dict(x=[0, 0.5]),
name = “Proportion de films ayant pour genre principal”),
row = 1, col = 1)
fig.add_trace(go.Pie(
values = values2,
labels = genre1,
domain = dict(x=[0.5, 1.0]),
name = “Proportion de films ayant pour genre secondaire”),
row = 1, col = 2)
plot(fig)

For this result I worked with these 3 libraries :
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly.offline import plot

Maybe this will help others.