python matplotlib 画图保存图片简单例子

保存的时候遇到过保存空白图像的问题,是因为将plt.savefig('./test2.jpg')放到了plt.show()之后,只要先保存在显示就可以正常保存了。

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, 69, 1)
plt.plot(t, t, 'r', t, t**2, 'b')
label = ['t', 't**2']
plt.legend(label, loc='upper left')
plt.savefig('./test2.jpg')
plt.show()

想画出更炫酷的图,可以多看看官网的例子

猜你喜欢

转载自blog.csdn.net/m0_37052320/article/details/79640467