matplotlib—绘制饼状图pie

文章目录


官网链接

import matplotlib.pyplot as plt
plt.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
 startangle=0, radius=1, counterclock=True, wedgeprops=None, textprops=None, center=0, 0, frame=False, 
 rotatelabels=False, *, normalize=None, data=None)

常用参数:

  1. x即每个扇形的占比的序列或数组
  2. explode如果不是None,则是一个len(x)长度的数组,指定每一块的突出程度;突出显示
  3. labels为每个扇形提供标签的字符串序列
  4. colors为每个扇形提供颜色的字符串序列
  5. autopct如果它是一个格式字符串,标签将是fmt % pct。如果它是一个函数,它将被调用。
  6. shadow阴影
  7. startangle从x轴逆时针旋转,饼的旋转角度
import matplotlib.pyplot as plt

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'  # 定义标签
sizes = [15, 30, 45, 10]  # 每一块的比例
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']  # 每一块的颜色
explode = (0, 0.1, 0, 0)  # 突出显示,这里仅仅突出显示第二块(即'Hogs')

plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal')  # 显示为圆(避免比例压缩为椭圆)
plt.show()

在这里插入图片描述


如果对您有帮助,麻烦点赞关注,这真的对我很重要!!!如果需要互关,请评论留言!
在这里插入图片描述


猜你喜欢

转载自blog.csdn.net/weixin_46649052/article/details/115321326