python matplotlib同时画多个图

一.多个图不在一个板里画

from matplotlib import pyplot as plt
x1=['1','2','3']
y1=[4,5,6]
x2=[4,5,7]
y2=[7,8,9]
x3=[12,15,17]
y3=[70,80,90]
fig1=plt.figure()
fig2=plt.figure()
fig3=plt.figure()
ax1=fig1.add_subplot(111)
ax2=fig2.add_subplot(111)
ax3=fig3.add_subplot(111)
ax1.bar(x=x1,height=y1,width=0.5)
ax2.plot(x2,y2)
ax3.plot(x3,y3)
plt.show()

二,多个图,在一个板里画

from matplotlib import pyplot as plt
x1=['1','2','3']
y1=[4,5,6]
x2=[4,5,7]
y2=[7,8,9]
x3=[12,15,17]
y3=[70,80,90]
fig1=plt.figure()

ax1=fig1.add_subplot(311)
ax2=fig1.add_subplot(312)
ax3=fig1.add_subplot(313)
ax1.bar(x=x1,height=y1,width=0.5)
ax2.plot(x2,y2)
ax3.plot(x3,y3)
plt.show()
posted @ 2022-10-17 15:51  mghhz816  阅读(944)  评论(0编辑  收藏  举报