简体   繁体   English

Python Matplotlib plt.show()不返回图

[英]Python Matplotlib plt.show() does not return the figure

I remote login a server using ssh -X ***@remote.arizona.edu (This remote server is a Linux system) and tried to make some plots using Python, I had the following errors: 我使用ssh -X ***@remote.arizona.edu (此远程服务器是Linux系统)远程登录服务器,并尝试使用Python进行一些绘图,出现以下错误:

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

Then I fixed this error by the adding the commands before I import any matplotlib : 然后在导入任何matplotlib之前,通过添加命令来修复此错误:

import matplotlib
matplotlib.use('Agg')
matplotlib.matplotlib_fname()

Now it runs well. 现在运行良好。 But the problem is that there is no figure displayed even if I had the command plt.show() . 但是问题是,即使我有命令plt.show() ,也没有显示任何数字。 My old computer used Ubuntu 16.04 before, there is no such problem. 我的旧计算机以前使用过Ubuntu 16.04,没有这样的问题。 Now I switched to MacBook Air, then I had this issue. 现在我改用MacBook Air,然后遇到了这个问题。 It must be some Mac setting issues. 这一定是Mac设置方面的问题。 Any thoughts to fix this issue? 有什么想法可以解决此问题?

You need to install XQuartz on your Macbook. 您需要在Macbook上安装XQuartz Then make sure the DISPLAY variable in your remote shell is set to your local X server. 然后,确保将远程外壳程序中的DISPLAY变量设置为本地X服务器。 Now the remote matplotlib should show the figure on your Macbook. 现在,远程matplotlib应该会在Macbook上显示该图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM