matplotlib/pylab plotting SSH tunnels and backends
Originally published on craneium.net
I recently discovered that tunneled connections using matplotlib force X11 to cram the entire figure across a slow SSH connection, even if the figure will never be rendered! To fix this, simply use the backend that requires no X11 support:
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import (plot, figure, psd, hist, savefig, close, title, xlabel, ylabel, axis)
from matplotlib.mlab import detrend_linear
This way there is (virtually) no SSH traffic overhead to plotting and saving figures!! Yay! Enjoy!