gpt4 book ai didi

python - 更改 matplotlib fiddle 图的颜色

转载 作者:IT老高 更新时间:2023-10-28 20:59:50 26 4
gpt4 key购买 nike

有没有办法改变 matplotlib 中 violin 绘图的颜色?

默认颜色是这种“棕色”颜色,这还不错,但我想给例如前 3 把 fiddle 上色以突出它们。我在 documentation 中没有找到任何参数.有什么想法或技巧可以给 fiddle 上色吗?

enter image description here

最佳答案

matplotlib.pyplot.violinplot()说它返回:

A dictionary mapping each component of the violinplot to a list of the corresponding collection instances created. The dictionary has the following keys:

  • bodies: A list of the matplotlib.collections.PolyCollection instances containing the filled area of each violin.
  • [...among others...]

PolyCollections 的方法包括:

所以,看起来你可以遍历结果的正文列表并修改每个的 facecolor:

violin_parts = plt.violinplot(...)

for pc in violin_parts['bodies']:
pc.set_facecolor('red')
pc.set_edgecolor('black')

虽然在创建它时不能像常见的绘图类型一样设置它,但有点奇怪。我猜这可能是因为该操作创建了太多位(前面提到的 PolyCollection 以及其他 5 个 LineCollections),所以附加参数会模棱两可。

关于python - 更改 matplotlib fiddle 图的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26291479/

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