5

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?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

if we're running the code on ubuntu for windows, how can we get a plot to "show up". Maybe decorate .show() to just savefig as png in a windows folder and have some tool monitoring the folder and showing images? better way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.