如何在饼图 matplotlib 上生成更多颜色 [英] How can I generate more colors on pie chart matplotlib

查看:137
本文介绍了如何在饼图 matplotlib 上生成更多颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过 40 个项目要显示在我的图表中.我只有 10 种颜色在图表上重复显示.我怎样才能产生更多的颜色.

I am having more then 40 items to show in my chart. I have only 10 colours that repeatedly are shown on the chart. How can I generate more colors.

plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True)

我应该在无限生成颜色的地方添加color=colors"吗?

I should add "color=colors" where colors is generated infinitely ?

推荐答案

你需要 colors 参数,此外你可以使用一些来自 cm 的颜色映射.

You need colors argument, beside that you can use some color maps from cm.

import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
a=np.random.random(40)
cs=cm.Set1(np.arange(40)/40.)
f=plt.figure()
ax=f.add_subplot(111, aspect='equal')
p=plt.pie(a, colors=cs)
plt.show()

除了使用颜色图,还可以考虑使用 .set_color_cycle() 方法.请参阅此帖子:在 matplotlib 中绘制不同的颜色

Beside using colormaps, also consider using .set_color_cycle() method. See this post: plotting different colors in matplotlib

这篇关于如何在饼图 matplotlib 上生成更多颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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