Is there any way to change the labels size on a graphic?

In the image below used on pie chart tutorial we can se the labels for Oxygen, Hydrogen, Carbon_diode and Nitrogen, but for me these labels are too small. The percentage numbers are small too but I can change the percentage numbers according the docs, but I not found nothing about the label size. Is there any way to do it?

import plotly.graph_objects as go

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500, 2500, 1053, 500]

# Use `hole` to create a donut-like pie chart
fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
fig.show()

EDIT: also, how to do it if I’m using plotly express like:

import plotly.express as px
df = px.data.gapminder().query("year == 2007").query("continent == 'Europe'")
df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countries
fig = px.pie(df, values='pop', names='country', title='Population of European continent')
fig.show()

Hi @leonardofurtado welcome to the forums.

There must be a more elegant way to change this, but I did not have the time to dig deeper. It’s ugly, but works on my computer:

figure_dict = fig.to_dict()
figure_dict['layout']['template']['layout']['font'].update({'size':20})
changed_figure = go.Figure(figure_dict)
changed_figure.show()

BTW: Thanks for the examples. This makes it a lot easier to help :raised_hands:

1 Like

Hi @leonardofurtado !
I think the parameter you are looking for is textfont_size (trace param)

You can set it directly with go:

fig.add_pie(labels=labels, values=values, hole=.3, textfont_size=15)

And with px, you have to update the trace after the creation of the fig:

fig = px.pie(df, values='pop', names='country', title='Population of European continent')
fig.update_traces(textfont_size=15)
1 Like

I knew there had to be a way. Nice @Skiks!

1 Like

Hi @AIMPED and @Skiks , sorry for late reply. So, textfont_size will increase just the percentage text in the donut chart, I’m using it too. But I was talking about the names on the right:
image

They are too small and textfont_size don’t work in this case.

Take a look at the third last example of this:

1 Like

haa okayyy!
here (same for go and px, after the creation of the figure):

# font size of the legend title
fig.update_layout(legend_title_font_size=20)
# font size of the legend labels
fig.update_layout(legend_font_size=15)
1 Like