3
votes

My setup is that I run an ipython notebook remotely on a linux server and I connect to it from OSX via an ssh tunnel.

I can confirm that X forwarding works fine and from the same terminal where ipython is started from I can use gnuplot etc.

In the ipython session on my local machine when trying to do something like

import matplotlib as mpl
mpl.use("GTK3cairo")
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],'*-')

all I get is [<matplotlib.lines.Line2D at 0x54bcc90>]. I have tried various other backends, with the same results. When using %pylab inline the plots appear, but I'd like them in separate windows.

I suppose something is wrong with X forwarding still - what would be the best way to debug this? All suggestions welcome.

1
did you try plt.show() ? - plonser
Instead of an ssh tunel you can access the ipython notebook through a browser on your LAN using ipython.org/ipython-doc/1/interactive/public_server.html - wrdeman
@plonser: that sorted it out, thanks!!!! - albapa
@wrdeman: I have actually been doing that - what I really meant is that I access the server via an ssh tunnel. - albapa
1) don't use %pylab , use %matplotlib, 2) kernels are runned in sub-process that might not inherit the environment variable, so no X-Forward. - Matt

1 Answers

1
votes
  1. When connecting to the server, use -L (which does local port forwarding) instead of -X (which does graphical output forwarding) like this:

    ssh -L 8000:localhost:8888 your_user_name@your_server_ip
    
  2. In your code, use %matplotlib inline before you import the pyplot to load the backend upfront and end with ; like this:

    %matplotlib inline
    from matplotlib import pyplot as plt
    
    plt.figure()
    plt.imshow(sample_image)
    plt.show();