Matplotlib: display plot on a remote machine

后端 未结 8 1523
天涯浪人
天涯浪人 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:31

    I have used IPython to solve the related problem. The steps are as follows:

    Step 1: Install IPython and Jupyter in the remote machine (A) locally (assuming no root privilege) using the following commands:

    pip install --user ipython
    pip install --user jupyter 
    

    Update matplotlib:

    pip install --user -U matplotlib
    

    Step 2:

    Run Jupyter with no browser from the code directory in the remote machine (A):

    cd PATH/TO/THE/CODE
    jupyter notebook --no-browser --port=8080
    

    After this command, a URL will be given something similar to below:

    http://localhost:8080/?token=5528ab1eeb3f621b90b63420f8bbfc510edf71f21437c4e2

    Step 3:

    Now open another terminal in the local machine (B) and connect to the remote machine (A) using ssh:

    ssh -N -L 8080:localhost:8080 user_id@remote.host
    

    The port number has to be same in step 2 and step 3. In this example, the port number is 8080.

    Step 4:

    Copy and paste the URL in the step 3 to a browser in your local machine (B).

    Now, the notebook in the remote machine can be used through the browser and plot can be generated using the data in the remote machine.

提交回复
热议问题