x = [1,10,5,14,45,26,17,8,9]
y = [[2,8,9,10,33,19,32,22,5],
[10,20,30,40,50,60,70,80,90],
[9,8,7,6,5,4,3,2,1],
[10,20,30,40,39,16,27,36,15]]
# 可视化(保存单个子图)
import matplotlib.pyplot as plt
for i in range(4):
plt.plot(x[:],color='g',label='True')
plt.plot(y[:][i],color='pink',label='Predict')
plt.legend()
plt.savefig((str(i)+'.svg'), bbox_inches='tight')
#plt.show()
plt.cla()
plt.clf()
# 解注释plt.show(),这样就可以显示画布,
结果:(CSDN上不能上传svg的图片,这里用截图代替)
0.svg
1.svg
2.svg
3.svg
# 可视化(画在一张画布上并保存)
import matplotlib.pyplot as plt
#figsize(width, hight)画布大小
fig = plt.figure(figsi=(8,6),dpi=100)
c = 0
for i in range(4):
c += 1
ax = fig.add_subplot(2, 2, c)
fig.suptitle("Predictions")
ax.plot(x[:],color='g',label='True')
ax.plot(y[:][i],color='pink',label='Predict')
ax.legend()
plt.savefig("predictions.svg")
plt.show()
plt.clf()