My Matplotlib backend keeps reverting to TkAgg. This is a problem because in the Windows Subsystem for Linux (WSL), you can't do GUI stuff, and so I get the error
TclError: no display name and no $DISPLAY environment variable
I've tried adding a matplotlibrc file to /home/<user>/.config/matplotlib (in the Windows filesystem, this is C:\Users\<user>\AppData\Local\lxss\home\<user>\.config\matplotlib).
My matplotlibrc looks like this
backend : Agg
However, if I do this
$ cd /home/<user>/.config/matplotlib
$ ls -A
nothing shows up.
When I try
 $ python
 >>> import matplotlib
 >>> matplotlib.get_backend()
 'TkAgg'
so clearly it's not setting the backend to Agg. Why not?
Update:
I've figured out that putting backend : Agg in C:\Users\<user>\AppData\Local\lxss\home\<user>\.config\matplotlib\matplotlibrc changes the backend in Windows Python only, leaving Linux Python as TkAgg. Which is odd, because Windows Python should only be using C:\Users\<user>\AppData\Local\Enthought\Canopy\User\Lib\site-packages\matplotlib\mpl-data\matplotlibrc, right?
I figured it out. I had created the matplotlibrc file using Windows - this is why it didn't show up when I tried $ ls -A in bash. So I did this instead (after deleting the Windows-created file):
$ cd /home/<user>/.config/matplotlib
$ touch matplotlibrc
$ echo "backend : Agg" > matplotlibrc
(touch matplotlibrc creates an empty matplotlibrc file)
This did the trick, and my Windows python matplotlib's backend was left as Qt4Agg.
Here it is on one line for copy/paste:
cd /home/<user>/.config/matplotlib; touch matplotlibrc && echo "backend : Agg" > matplotlibrc
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With