Python数据可视化(六):饼图绘制

使用matplotlib包绘制饼图

# library
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20,5)
# 绘制基础饼图
# create random data
values=[12,11,3,30]

# Create a pieplot
plt.pie(values);
plt.show();
image.png
# create random data
names='groupA', 'groupB', 'groupC', 'groupD',
values=[12,11,3,30]

# 设置labels参数添加标签
# Label distance: gives the space between labels and the center of the pie
plt.pie(values, labels=names, labeldistance=1.15);
plt.show();
image.png
# 自定义wedges
## Same chart as above but with specific wedgeprops option:
plt.pie(values, labels=names, labeldistance=1.2, 
        wedgeprops = { 'linewidth' : 3, 'edgecolor' : 'white' });
image.png
# 自定义饼图的填充色
# Create a set of colors
colors = ['#4F6272', '#B7C3F3', '#DD7596', '#8EB897']

# Use it thanks to the color argument
plt.pie(values, labels=names, labeldistance=1.15, 
        wedgeprops = { 'linewidth' : 1, 'edgecolor' : 'white' }, 
        colors=colors);
image.png

参考来源:https://www.python-graph-gallery.com/pie-plot/

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容