Python 使用Windows Subsystem for Linux时设置Matplotlib后端

Python 使用Windows Subsystem for Linux时设置Matplotlib后端,python,linux,matplotlib,windows-subsystem-for-linux,Python,Linux,Matplotlib,Windows Subsystem For Linux,我的Matplotlib后端一直恢复到TkAgg。这是一个问题,因为在Windows Linux子系统(WSL)中,您无法执行GUI操作,因此我得到了错误 Tcl错误:没有显示名称和$display环境变量 我已尝试将matplotlibrc文件添加到/home/.config/matplotlib(在Windows文件系统中,这是C:\Users\\AppData\Local\lxss\home\\\.config\matplotlib) 我的matplotlibrc如下所示 backend

我的Matplotlib后端一直恢复到
TkAgg
。这是一个问题,因为在Windows Linux子系统(WSL)中,您无法执行GUI操作,因此我得到了错误

Tcl错误:没有显示名称和$display环境变量

我已尝试将
matplotlibrc
文件添加到
/home/.config/matplotlib
(在Windows文件系统中,这是
C:\Users\\AppData\Local\lxss\home\\\.config\matplotlib

我的
matplotlibrc
如下所示

backend : Agg
然而,如果我这样做

$ cd /home/<user>/.config/matplotlib
$ ls -A
很明显,它没有将后端设置为
Agg
。为什么不呢

更新:


我发现在
C:\Users\\AppData\Local\lxss\home\\.config\matplotlib\matplotlibrc
中放置
backend:Agg
只会更改Windows Python中的后端,而将Linux Python保留为
TkAgg
。这很奇怪,因为Windows Python应该只使用
C:\Users\\AppData\Local\enthund\Canopy\User\Lib\site packages\matplotlib\mpl data\matplotlibrc
,对吗?

我已经猜到了。我使用Windows创建了matplotlibrc文件-这就是为什么我在bash中尝试
$ls-A
时它没有显示出来。因此,我改为(在删除Windows创建的文件后):


事实上,如果我们在ubuntu for windows上运行代码,我们怎么能得到一个“显示”的图呢。也许decoration.show()只是将Fig保存为windows文件夹中的png,并使用一些工具监视文件夹并显示图像?更好的方法?
 $ python
 >>> import matplotlib
 >>> matplotlib.get_backend()
 'TkAgg'
$ cd /home/<user>/.config/matplotlib
$ touch matplotlibrc
$ echo "backend : Agg" > matplotlibrc
cd /home/<user>/.config/matplotlib; touch matplotlibrc && echo "backend : Agg" > matplotlibrc