更改Matplotlib饼图中的线属性 [英] Changing line properties in matplotlib pie chart

查看:41
本文介绍了更改Matplotlib饼图中的线属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使matplotlib饼图上的线条更浅一些.因为我有很多切片,所以线条太粗了,如下所示:

I'm trying to make the lines on my matplotlib pie chart much lighter. Because I have so many slices, the lines are way too thick, as shown here:

我阅读了 这个例子,它建议使用 rcparam 之类的这个:

I read this example which suggests using rcparam like this:

matplotlib.rcParams['text.color'] = 'r'
matplotlib.rcParams['lines.linewidth'] = 2

但是,尽管我可以更改文本颜色,但它不会更改饼图切片之间的线条的宽度.我相信这是因为切片不是由线对象控制的,而是由楔形对象控制的.那么有没有办法设置楔形边框的样式和颜色呢?

but although I can change the text color, it doesn't change the width of the lines between the pie slices. I believe that's because the slices aren't governed by line objects but by wedge objects. So is there a way to set the wedge border style and color?

非常感谢,亚历克斯

推荐答案

尝试一下:

ax = plt.subplot(111) 
wedges, texts = ax.pie(np.abs(np.random.randn(5)))

for w in wedges:
    w.set_linewidth(2)
    w.set_edgecolor('cyan')

此外,如果您只有一个 axes 对象并且无法直接访问饼图的楔形,您可以从 ax.patches 中检索楔形:

Additionally, if you only have an axes object and don't have direct access to the pie's wedges you can retrieve the wedges from ax.patches:

wedges = [patch for patch in ax.patches if isinstance(patch, matplotlib.patches.Wedge)]

这篇关于更改Matplotlib饼图中的线属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆