在linux终端上使用python的matplotlib绘制图形

实验条件:

MobaXterm(下文简称moba)或其他具备x server功能的终端

实验过程:

  1. 通过moba连上linux服务器后,开启x server功能(在菜单栏"X server")
  2. 确保已经安装python的matplotlib库
  3. 运行以下代码:
import matplotlib
matplotlib.use('Tkagg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt

fig1 = plt.figure()
plt.plot(range(10))
fig1.savefig('f1.png')
#plt.show()

fig2 = plt.figure()
plt.plot(range(3))
fig2.savefig("f2.png")
plt.show()

实验结果:

绘图程序会产生两张图。这两张图会通过x server绘制,也会保存在脚本所在目录下。
其中一张图展示如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/canwhut/article/details/82817653