linux终端的python绘图实现方式

xiaoxiao2021-03-01  2

linux终端利用python绘图时有两种方法:

(1)一种是添加如下代码中红色部分:from tensorflow.examples.tutorials.mnist import input_dataimport matplotlib.pyplot as pltplt.switch_backend("agg")mnist=input_data.read_data_sets("MNIST_data",one_hot=True)print(mnist.train.images.shape)print(mnist.train.labels[1])image=mnist.train.images[1,:]image=image.reshape(28,28)plt.figure()plt.imshow(image)plt.show()plt.savefig('plot2.png', format='png')(2)也可以添加下面三行,注意前后顺序

import numpy as np import matplotlib as mplmpl.use('agg') import matplotlib.pyplot as plt xData=np.arange(0,10,1) yData1=xData.__pow__(2.0) yData2=np.arange(15,61,5) plt.figure(1) plt.title('Plot 1',size=14) plt.xlabel('x-axis',size=14) plt.ylabel('y-axis',size=14) plt.plot(xData,yData1,color='b',linestyle='--',marker='o',label='y1 data') plt.plot(xData,yData2,color='r',linestyle='-',marker='o',label='y2 data') plt.legend(loc='upper left') plt.show() plt.savefig('plot1.png',format='png')
转载请注明原文地址: https://www.6miu.com/read-3850128.html

最新回复(0)