您的位置:首页 > 其它

_tkinter.TclError: no display name and no $DISPLAY environment variable的问题

2018-01-18 12:26 1041 查看
升级了matplotlib ,但发现绘图脚本不能用了。报错:>>> plt.figure(figsize=(30,20))Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 527, in figure    **kwargs)  File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager    return new_figure_manager_given_figure(num, figure)  File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure    window = Tk.Tk()  File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1810, in __init__    self.tk = _tkinter.create(screenName, baseName, className, interacti_tkinter.TclError: no display name and no $DISPLAY environment variable解决:在脚本导入任何库之前,运行:
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
举例:
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as pltimport numpy as npx = np.random.randn(60)y = np.random.randn(60)plt.scatter(x, y, s=20)out_png = 'path/to/store/out_file.png'plt.savefig(out_png, dpi=150)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐