It seems to me that I can only add one line of annotation at the center of a donut chart using a f-string for the “text” property of the .add_annotation function of a donut chart.
What if I want to add multi-line text for this annotation, e.g., showing “Total Value” above the numerical value?
I don’t know if I understand your purpose correctly, but if you want to add a multi-line annotation in the center of a doughnut graph, you can use string merging. I have slightly modified the data for the donut graph example in the reference.
import plotly.graph_objects as go
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [45.00, 25.00, 10.53, 5.00]
# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.add_annotation(
x=0.5,
y=0.5,
text='total values:<br>'+f'{round(sum(values),2):,}',
font=dict(size=16, weight='bold'),
showarrow=False,
)
fig.update_layout(height=600)
fig.show()