Python Matplotlib plt.show() 没有return 的图
Python Matplotlib plt.show() does not return the figure
我使用 ssh -X ***@remote.arizona.edu
远程登录服务器(此远程服务器是 Linux 系统)并尝试使用 Python 绘制一些图,但出现以下错误:
_tkinter.TclError: no display name and no $DISPLAY environment variable
然后我通过在导入任何 matplotlib
:
之前添加命令来修复此错误
import matplotlib
matplotlib.use('Agg')
matplotlib.matplotlib_fname()
现在运行良好。但问题是即使我有命令 plt.show()
也没有数字显示。我的老电脑以前用的是Ubuntu16.04,没有这个问题。现在我切换到 MacBook Air,然后我遇到了这个问题。这一定是一些 Mac 设置问题。有解决此问题的想法吗?
您需要在您的 Macbook 上安装 XQuartz。然后确保远程 shell 中的 DISPLAY 变量设置为本地 X 服务器。现在遥控器 matplotlib
应该会在你的 Macbook 上显示这个数字。
我使用 ssh -X ***@remote.arizona.edu
远程登录服务器(此远程服务器是 Linux 系统)并尝试使用 Python 绘制一些图,但出现以下错误:
_tkinter.TclError: no display name and no $DISPLAY environment variable
然后我通过在导入任何 matplotlib
:
import matplotlib
matplotlib.use('Agg')
matplotlib.matplotlib_fname()
现在运行良好。但问题是即使我有命令 plt.show()
也没有数字显示。我的老电脑以前用的是Ubuntu16.04,没有这个问题。现在我切换到 MacBook Air,然后我遇到了这个问题。这一定是一些 Mac 设置问题。有解决此问题的想法吗?
您需要在您的 Macbook 上安装 XQuartz。然后确保远程 shell 中的 DISPLAY 变量设置为本地 X 服务器。现在遥控器 matplotlib
应该会在你的 Macbook 上显示这个数字。