Matplotlib: display plot on a remote machine

后端 未结 8 1507
天涯浪人
天涯浪人 2020-11-28 19:45

I have a python code doing some calculation on a remote machine, named A. I connect on A via ssh from a machine named B. Is there a way to display the figure on

8条回答
  •  执念已碎
    2020-11-28 20:44

    If you use matplotlib on Mac OS X on the remote machine (B), you must first make sure that you use one of the X11-based display back-ends, since the native Mac OS X back-end cannot export its plots to another display. Selecting a back-end can be achieved with

    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.

提交回复
热议问题