Black Lives Matter. Please consider donating to Black Girls Code today.

Display values instead of percentage in Plotly Pie chart

I want the values to be displayed in pie chart instead of the percentages, there is no property to display the numbers instead of the percentages. Please suggest.


Sample code to generate the pie chart:

import as px
import pandas as pd
def my_view(request):
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
a=os.path.join(BASE_DIR, ‘db.sqlite3’)
con = sqlite3.connect(a)
cur = con.cursor()
df = pd.read_sql_query(“SELECT * from POL”, con)
esd = df.groupby(‘ProjectStatus’, as_index=False).agg({“ProjectID”: “count”})
fig = px.pie(esd, values=Tasks, names=my_labels, color_discrete_sequence=px.colors.sequential.Blugrn)
graph = fig.to_html(full_html=False, default_height=350, default_width=500)
context = {‘graph’: graph}
response = render(request, ‘Home.html’, context)

Hello, and welcome to the community forum.

In order to display raw values rather than percentages in pie charts, you can set the textinfo attribute to value. For example:

import as px
# This dataframe has 244 lines, but 4 distinct values for `day`
df =
fig = px.pie(df, values='tip', names='day')

Hope that helps!

1 Like

Simply great!! It worked…
Didn’t find the update_traces method in plotly’s documentation, could you please provide the URL for full documentation if possible.

Glad I could help you solve your issue. The documentation for the update_traces method is:

1 Like

Thanks, have a good day ahead!!