In [117]: import matplotlib.pyplot as plt
In [118]: data = [5,25,50,20]
plt.pie(data)
plt.show()
4 Using custom colors for pie charts
In [29]: import numpy as np
import matplotlib.pyplot as plt
In [35]: values = np.random.rand(8)#generating 8 numbers with 0<=values<1
color_set = ('.00', '.25', '.50', '.75')
#If there are less colors than values, then pyplot.pie() will simply cycle through the color li
#each color will be used twice.in our example
In [37]: plt.pie(values, colors=color_set)
plt.show()

本文介绍了如何使用Python的Matplotlib库绘制基本的饼图,并进一步展示了如何通过自定义颜色来增强饼图的视觉效果。首先,我们创建了一个简单的数据集并用其绘制了一个基本的饼图。接着,我们生成了一组随机数并使用特定的颜色集合来绘制第二个饼图,展示了当颜色数量少于数据值时,Matplotlib如何自动循环使用颜色。
275

被折叠的 条评论
为什么被折叠?



