Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a progress pie chart using plotly from a percentage value?

If there is a variable like

x = 80

or a dataframe like

progress
0 80

Then how do I create a chart like the one below
enter image description here

like image 714
imdevskp Avatar asked Dec 13 '25 12:12

imdevskp


1 Answers

You can use:

df = pd.DataFrame({'names' : ['progress',' '],
                   'values' :  [progress, 100 - progress]})

fig = px.pie(df, values ='values', names = 'names', hole = 0.5,
             color_discrete_sequence = ['FC0080', 'rgba(0,0,0,0)']
            )

And get:

enter image description here

Complete code:

import plotly.express as px
import pandas as pd

# data
progress = 80
df = pd.DataFrame({'names' : ['progress',' '],
                   'values' :  [progress, 100 - progress]})

# plotly
fig = px.pie(df, values ='values', names = 'names', hole = 0.5,
             color_discrete_sequence = ['red', 'rgba(0,0,0,0)']
            )

fig.data[0].textfont.color = 'white'
# fig.show()
fig.show()

f = fig.full_figure_for_development(warn=False)
fig.show()
like image 97
vestland Avatar answered Dec 15 '25 21:12

vestland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!