"ssh -X" doesn't open matplotlib figures

4

1

Often times, I ssh into another computer to do python work. While I'm coding, I like to have an ipython shell open for quick testing. For some reason, I cannot get matplotlib to open figures. Here is an example:

[mwoods@linux_box ~]$ ssh -X me@mac_machine
Password:
Last login: Fri Dec 15 13:03:37 2017
mwoods:~ /path/to/ipython
Python 3.6.3 |Anaconda, Inc.| (default, Oct 6 2017, 12:04:38)
Type ‘copyright’, ‘credit’ or ‘license’ for more information
IPython 6.1.0 — An enhanced Interactive Python. Type ‘?’ for help.

In [1]: import matplotlib as mpl

In [2]: mpl.use('Agg')

In [3]: import matplotlib.pyplot as plt

In [4]: import numpy as np

In [5]: plt.ion()

In [6]: plt.imshow(np.random.rand(8, 8))
Out[6]: <matplotlib.image.AxesImage at hex_number>

In [7]: 

No plot opens. As shown, I start from a linux box and ssh into a Macintosh (I have admin privileges on the mac). The mac runs on macOS Sierra (10.12.6) and has Anaconda version 5.0.1 installed. Other X11 forwarding commands (e.g. xpdf, display) work over the same ssh connection, so I don't think it has to do with the ssh_config or sshd_config files on either machine. Could someone please help?

mwoods

Posted 2017-12-18T19:14:23.033

Reputation: 41

2This is an interesting problem. You might need to migrate it to Super User, but it's a good question either way. – cwallenpoole – 2017-12-18T19:23:04.217

Can you tell us what backend is being used? That might need some help to be forwarded through the connection. https://stackoverflow.com/q/3580027/2449192

– darthbith – 2017-12-18T21:16:47.313

@darthbith I edited the post to show a backend. The default is MacOSX, but that doesn't work. I tried Agg (as shown above), but that also doesn't work. I then tried GTK and GTKAgg, but I don't have pygtk. I tried "conda install -c mw gtk2", but I get an HTTP error. It tells me to keep trying, but I'm not having any luck with it. – None – 2017-12-18T22:47:21.490

Answers

0

Maybe give the -Y flag to ssh a try in place of -X. See documentation of the ForwardX11Trusted option for what might be going on.

J. Scott Berg

Posted 2017-12-18T19:14:23.033

Reputation: 61

I should have mentioned above that I have tried this. Both -X and -Y flags don't open matplotlib figures. Although, as mentioned in the original post, both flags work for programs like xpdf and ImageMagick. – mwoods – 2018-01-02T16:00:28.600