gpt4 book ai didi

python - pygal:多系列饼图上的标签

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:54 24 4
gpt4 key购买 nike

如何在 multiseries pie chart 的次要系列上添加标签?

最佳答案

一种方法是将您的值作为字典传递。

首先导入一些需要的包

import pygal
from pygal.style import LightGreenStyle

初始化 Pygal Pie 对象。您可以忽略花哨的主题(LightGreenStyle)。

pie_chart = pygal.Pie(width=900, height=500, 
style=LightGreenStyle,
value_formatter=lambda x: "{}%".format(x))

这是你想要的部分。

pie_chart.title = 'Wine Quality Percentage'

pie_chart.add('Good Wines', [{'value': wine_quality_8_percent, 'label': 'Quality Rating - 8'}])

pie_chart.add('Average Wines', [{'value': wine_quality_5_percent, 'label': 'Quality Rating - 5'},
{'value': wine_quality_6_percent, 'label': 'Quality Rating - 6'},
{'value': wine_quality_7_percent, 'label': 'Quality Rating - 7'}
])

pie_chart.add('Poor Wines', [{'value': wine_quality_3_percent, 'label': 'Quality Rating - 3'},
{'value': wine_quality_4_percent, 'label': 'Quality Rating - 4'}])

请注意,值作为带有“值”和“标签” 的字典传入。这将使您的标 checkout 现在您的多系列 Pie 中。

enter image description here

这与常规饼图中的标签相似 - Using PyGal, how can I embed a label on the pie chart itself on hover?

关于python - pygal:多系列饼图上的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337638/

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