Q:

Matplotlib Backend issue _tkinter.TclError: no display name and no $DISPLAY environment variable

I am trying to plot a simple graph using matplotlib while connecting to Linux machine using SSH. I am running my code on Python2.7 
I ran the following first:
import matplotlib
print(matplotlib.get_backend())

where I got the "TkAgg" as my backend 
Then I ran:
import os
import matplotlib as mpl
if os.environ.get('DISPLAY','') == '':
    print('no display found. Using non-interactive TkAgg backend')
    mpl.use('TkAgg')
import matplotlib.pyplot as plt 

to make sure TkAgg is specifically used. Yet it returns: _tkinter.TclError: no display name and no $DISPLAY environment variable error.
Interestingly when I use "Agg" just to see what happens, No Error shows up and No graphs either.
Any kind suggestions?

A:

The Agg backend doesn't display anything, it is used when you want to save the plot without making it appear.
What you want is to forward your display from where you are, so ssh -X or ssh -Y.
See https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely

