VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • Matplotlib数据可视化(6):饼图与箱线图

1 饼图-pie()

回到顶部

1.1 pie()方法参数说明

pie()是matplotlib中画饼图的方法,其主要参数如下:

回到顶部

1.2 基础作图

In [3]:
labels = 'Python组', 'Java组', 'C组', 'Go组'
sizes = [25, 45, 30, 10]

fig = plt.figure(figsize=(8, 4))
ax1 = fig.add_subplot(111)

ax1.pie(sizes, labels=labels)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()
 
回到顶部

1.3 字符标签与数值标签

In [4]:
labels = 'Python组', 'Java组', 'C组', 'Go组'
sizes = [25, 45, 30, 10]

fig = plt.figure(figsize=(8, 4))

ax1 = fig.add_subplot(121)
ax1.pie(sizes, 
        labels=labels,   # 字符标签
        labeldistance=1.1,  # 字符标签到中心点的距离
        autopct='%1.1f%%',  # 显示数值标签
        pctdistance=0.5   #数值标签到中心点的距离
       )

ax2 = fig.add_subplot(122)
ax2.pie(sizes, 
        labels=labels,   # 字符标签
        labeldistance=0.4,  # 字符标签到中心点的距离
        autopct='%1.2f%%',  # 显示数值标签
        pctdistance=1.2,   #数值标签到中心点的距离
        rotatelabels=True  # 旋转标签
       )
plt.show()

相关教程