Python语言学习

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

2021-05-03  本文已影响0人  Davey1220

使用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/

上一篇下一篇

猜你喜欢

热点阅读