gpt4 book ai didi

python - 如何使用百分比值绘制进度饼图?

转载 作者:行者123 更新时间:2023-12-05 03:42:57 27 4
gpt4 key购买 nike

如果有一个像这样的变量

x = 80

或者类似的数据框

<表类="s-表"><头><日> 进展<正文>080

那么我该如何创建如下图所示的图表
enter image description here

最佳答案

您可以使用:

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)']
)

并得到:

enter image description here

完整代码:

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()

关于python - 如何使用百分比值绘制进度饼图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67064105/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com