繁体   English   中英

使用Windows子系统Linux时设置Matplotlib后端

[英]Set Matplotlib backend when using Windows Subsystem for Linux

我的Matplotlib后端一直在恢复TkAgg 这是一个问题,因为在Windows子系统Linux(WSL)中,你不能做GUI的东西,所以我得到错误

TclError:没有显示名称和没有$ DISPLAY环境变量

我试着加入matplotlibrc文件/home/<user>/.config/matplotlib (在Windows文件系统,这是C:\\Users\\<user>\\AppData\\Local\\lxss\\home\\<user>\\.config\\matplotlib )。

我的matplotlibrc看起来像这样

backend : Agg

但是,如果我这样做

$ cd /home/<user>/.config/matplotlib
$ ls -A

没有出现。

当我尝试

 $ python
 >>> import matplotlib
 >>> matplotlib.get_backend()
 'TkAgg'

很明显,它没有将后端设置为Agg 为什么不?

更新:

我已经发现C:\\Users\\<user>\\AppData\\Local\\lxss\\home\\<user>\\.config\\matplotlib\\matplotlibrc backend : AggC:\\Users\\<user>\\AppData\\Local\\lxss\\home\\<user>\\.config\\matplotlib\\matplotlibrc backend : Agg仅更改Windows Python中的后端,将Linux Python保留为TkAgg 这很奇怪,因为Windows Python应该只使用C:\\Users\\<user>\\AppData\\Local\\Enthought\\Canopy\\User\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc ,对吧?

我想到了。 我使用Windows创建了matplotlibrc文件 - 这就是为什么当我在bash中尝试$ ls -A时它没有显示出来的原因。 所以我做了这个(删除Windows创建的文件后):

$ cd /home/<user>/.config/matplotlib
$ touch matplotlibrc
$ echo "backend : Agg" > matplotlibrc

touch matplotlibrc创建一个空的matplotlibrc文件)

这样做了,我的Windows python matplotlib的后端留下了Qt4Agg。


这是复制/粘贴的一行:

cd /home/<user>/.config/matplotlib; touch matplotlibrc && echo "backend : Agg" > matplotlibrc

暂无
暂无

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

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