Python - 如何在饼图中将 autopct 文本颜色更改为白色? [英] Python - How to change autopct text color to be white in a pie chart?
本文介绍了Python - 如何在饼图中将 autopct 文本颜色更改为白色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pie(fbfrac,labels = fblabel,autopct='%1.1f%%',pctdistance=0.8,startangle=90,colors=fbcolor)
我已经按照我想要的方式显示了图表,但如果文本是白色而不是黑色,它会在图中更好地突出显示.
I have the chart displaying just as I want it, with the exception that the text will stand out better inside the plot if it is white instead of black.
推荐答案
来自 pyplot.pie
文档:
返回值:
如果autopct不为None,则返回元组(补丁,文本,自动图文集),其中补丁和文本如上,而自动图文集是数字标签的文本实例.
If autopct is not None, return the tuple (patches, texts, autotexts), where patches and texts are as above, and autotexts is a list of Text instances for the numeric labels.
你需要改变autotexts
的颜色;这只需通过 set_color()
:
You need to change the color of autotexts
; this is done simply by set_color()
:
_, _, autotexts = pie(fbfrac,labels = fblabel,autopct='%1.1f%%',pctdistance=0.8,startangle=90,colors=fbcolor)
for autotext in autotexts:
autotext.set_color('white')
这产生(使用猪和狗的例子):
这篇关于Python - 如何在饼图中将 autopct 文本颜色更改为白色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文