plot() connects to display with ssh -X

Viewed 81

I am working with a slow ssh-connection to a server. I want to save a figure like

#1
import matplotlib.pyplot as plt
plt.plot([1,2,4])
plt.plot([1,3,4])
#...
plt.savefig("foo.jpg")

and show it with

feh foo.png

because feh is fast. Note there is no plt.show()

But the code #1 is still very slow as long as I'm running ssh -X, because every plot()-instance connects to the display. If -X is left out it's fast, but then another connection is needed for the feh...

What is the reason for plot() connecting to the display and can it be avoided?

1 Answers

I found a workaround. In a vscode or tmux session with X-forwarding, in one terminal do export DISPLAY= and here you can run the script fast, and do graphical stuff, like feh, in another terminal pane.

And for the record, jpg (2 sec) is considerably faster than png (4 sec) or pdf (6 sec) when shown with feh or xpdf.

Related