Python 从终端运行matplotlib以生成和保存图形

Python 从终端运行matplotlib以生成和保存图形,python,matplotlib,Python,Matplotlib,是否可以从纯文本控制台运行matplotlib?我正在使用matplotlib生成一些图形,并使用fig.savefig()保存它。 因此,基本上,图形是在后台生成的,并保存在文件系统中 错误是 self.fig1 = plt.figure(figsize=plt.figaspect(aspect_ratio)) File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 535, in figur

是否可以从纯文本控制台运行matplotlib?我正在使用matplotlib生成一些图形,并使用
fig.savefig()
保存它。 因此,基本上,图形是在后台生成的,并保存在文件系统中

错误是

    self.fig1 = plt.figure(figsize=plt.figaspect(aspect_ratio))
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 535, in figure
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

@Y.Luo的可能副本-事实上。。非常感谢。也许,我用的是terminal而不是ssh,搜索时没有出现。欢迎!