Pareparing your remote server

Login to your remote server.

ssh username@remotehost 

Install what we need

$ sudo apt install xorg xauth openssh-server

Change parameters of ‘/etc/ssh/sshd_config’ like below

...
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
UseLogin no
...

Restart remote ssh server

$ service ssh restart

Preparing your mac

Make sure you have installed X11 on your local machine

$ brew cask install xquartz
$ ssh -CY username@remotehost
$ echo $DISPLAY # veryfy that your `DISPLAY` is not empty
$ xeyes # verify you have X11

Plot with matplotlib

import matplotlib
# matplotlib.use('TkAgg') # if you can't see any window, then set TkAgg as backend
import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.show()