Sure, you can enable X11 forwarding. Usually this is done by passing the -X or -Y option to ssh when you connect to the remote computer
ssh -X computerA
Note that the SSH daemon on computer A will also have to be configured to enable X11 forwarding. This is done by putting
X11Forwarding yes
in computer A's sshd_config configuration file.
If computer A's SSH daemon does not have X11 forwarding enabled, you can always have Python write the result of the calculation to a text file, download it to computer B, and use Matplotlib locally.
如果在远程计算机(B)上的Mac OS X上使用matplotlib,则必须首先确保使用基于X11的显示后端之一,因为本机Mac OS X后端无法将其绘图导出到其他显示。选择后端可以通过以下方式实现
import matplotlib
matplotlib.use('GTK') # Or any other X11 back-end
The list of supported back-ends can be obtained by giving use() an incorrect back-end name: matplotlib then prints an error message listing the possible back-ends.
ssh X11 forwarding can then be used to display matplotlib plots.
The following worked for me using Mac OS X on the local machine (machine B) and ubuntu on the remote (machine A).
You need X11 server installed on your local machine to do this.
If you're running a recent version of Mac OSX (OS X Mountain Lion or newer), it would NOT have come with X11 pre-installed (see http://support.apple.com/kb/ht5293). Check if you have X11 by opening up Mac terminal, and run command xterm.
If an X11 window opens up, you're all set. If it says command not found, then go to http://xquartz.macosforge.org/landing/ and install X11 server. Then logout and log back in to your mac.
After you log back in, try to run xterm command again. It should open up X11 window.
At this point your $DISPLAY variable should also be set correctly. If it's not set, make sure you've logged in/out since installing X11 from XQuartz.
Then from your local machine, use ssh -X to remote into remote machine A:
ssh -X user@machineA
Then on the remote machine:
python
>>> import matplotlib
>>> matplotlib.use('GTKAgg') #I had to use GTKAgg for this to work, GTK threw errors
>>> import matplotlib.pyplot as plt #... and now do whatever you need...
Make sure you call matplotlib.use BEFORE importing anything else from matplotlib (e.g. matplotlib.pyplot)
Just wanted to add - if you're on Windows as the local machine, make sure you've set up Xming (an X Windows server) and Putty so you can see the remote Linux graphical applications.
Both GTK2 and GTK3 have implicit dependencies on PyCairo regardless of
the specific Matplotlib backend used. Unfortunatly the latest release
of PyCairo for Python3 does not implement the Python wrappers needed
for the GTK3Agg backend. Cairocffi can be used as a replacement which
implements the correct wrapper.
Forwarding the display
Install launch the latest version of XQuartz.
Connect to the remote server using ssh -X. ex) ssh username@ipaddress -X
It uses the exact same API as matplotlib, but it renders the plots in a web browser which you can view from your machine B.
Install by:
pip install remote_plot
And then run in python like this:
from remote_plot import plt
plt.plot([1, 2, 3], [4, 5, 6])
By default it opens the rendering on port 8000 but you can modify this easily. If you are connecting via ssh, don't forget to forward the port by adding the following flag to your ssh command: