用Python中的matplotlib画出一个3行2列的饼图

下面给出一个利用Python中的matplotlib画出一个3行2列的饼图,大家想参考画图多行多列图形的可以参考下这个小例子哦!

祝大家生活愉快!

代码:

import numpy as np
import matplotlib.pyplot as plt
import pylab as pl
from pyecharts import Pie
#画出3行2列的饼图

labels = ['Flat','Reduce','Raise']
# 321 > 3行2列第1个
fig1 = pl.subplot(321)
pl.pie([12,1,7],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.axis('equal')
plt.title("group A_20min")

# 322 > 3行2列第2个
fig2 = pl.subplot(322)
pl.pie([2,2,1],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.axis('equal')
plt.title("group B_20min")

# 323 > 3行2列第3个
fig3 = pl.subplot(323)
pl.pie([8,2,10],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.axis('equal')
plt.title("group A_60min")

# 324 > 3行2列第4个
fig4 = pl.subplot(324)
pl.pie([2,1,2],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.axis('equal')
plt.title("group B_60min")

# 325 > 3行2列第5个
fig5 = pl.subplot(325)
pl.pie([4,1,15],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)#startangle表示饼图的起始角度
plt.axis('equal') #这行代码加入饼图不会画成椭圆
plt.title("group A_70min")

# 326 > 3行2列第6个
fig6 = pl.subplot(326)
pl.pie([3,1,1],labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.axis('equal')
plt.title("group B_70min")

pl.tight_layout() #布局方法
pl.savefig('D:\\2018TianChiGame\pyecharts_demo\\vc5.jpg',dpi = 500) #dpi实参改变图像的分辨率
pl.show() #显示方法

运行结果:

猜你喜欢

转载自blog.csdn.net/qq_33221533/article/details/81568244