1. What I want to do
I want to set the “weight” to “bold” for the font of the annotation at the center of a donut chart, as shown below:
2. My code
Here’s the code:
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=0.3,
textinfo="label+value+percent",
)
]
)
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()
3. Error
I got the following error for the line font=dict(size=16, weight='bold')
, specifically:
ValueError: Invalid property specified for object of type plotly.graph_objs.layout.annotation.Font: 'weight'
Did you mean "size"?
Valid properties:
color
family
HTML font family - the typeface that will be applied by
the web browser. The web browser will only be able to
apply a font if it is available on the system which it
operates. Provide multiple font families, separated by
commas, to indicate the preference in which to apply
fonts if they aren't available on the system. The Chart
Studio Cloud (at https://chart-studio.plotly.com or on-
premise) generates images on a server, where only a
select number of fonts are installed and supported.
These include "Arial", "Balto", "Courier New", "Droid
Sans",, "Droid Serif", "Droid Sans Mono", "Gravitas
One", "Old Standard TT", "Open Sans", "Overpass", "PT
Sans Narrow", "Raleway", "Times New Roman".
size
Did you mean "size"?
Bad property path:
weight
^^^^^^
4. Looking for help
May I ask the source of this error, and the way to correct it?
Has the .add_annotation()
method been updated recently and the “weight” property is removed?
BTW, based on the suggestion from Claude.ai, it should work…
5. What I tried
I still got the same error warning after changing the code to use “weight = 100”, based on the document on font weight of annotation as shown below.