Hi Plotly Community.
I have subplots whose one of plot is PieChart. I tried multiple ways to place an annotation.
Here is my code which is not working.
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig_l = make_subplots(
rows=1, cols=2,
specs=[[{"type": "domain"},{"type": "xy"}]], print_grid=True)
fig_l.add_trace(go.Pie(labels=grouped_df_3['department'], values=grouped_df_3['counting'],
hole = .4),
row=1, col=1)
fig_l.add_trace(go.Bar(
x=group_salary['department'],
y=group_salary['placed_perc'],
name='Employed',
text = group_salary['placed_perc']),
row=1, col=2)
fig_l.add_trace(go.Bar(
x=group_salary['department'],
y=group_salary['not_placed_perc'],
name="Unemployed",
text=group_salary['not_placed_perc']
), row = 1, col = 2)
fig_l.add_annotation(xref='x domain',
yref='y domain',
x=0.01,
y=0.9,
text='Pie Chart',
showarrow=False,
row=1, col=1)
fig_l.add_annotation(xref='x domain',
yref='y domain',
x=0.01,
y=0.9,
text='Bar Chart',
showarrow=False,
row=1, col=2)
This is giving an error of
ValueError: Cannot add annotation to subplot at position (1, 1) because subplot is of type domain.
Then I tried
fig_l.update_layout(annotations=[dict(text='GHG', x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text='CO2', x=0.82, y=0.5, font_size=20, showarrow=False)])
This also not assigning any text to Pie Chart, instead assigning both texts to Bar Chart.
Would be grateful if anyone can help, thank you very much!