How to display Image in Ubuntu 16.04 terminal python 2.7 using matplotlib

I am Ubuntu 16.04 terminal, python 2.7 ,matplotlib.

I need to run python script “demo.py” ,which should display image

I check my backend using

>>>import matplotlib
>>>matplotlib.get_backend()
'TkAgg'

I put

matplotlib.use('Agg')

because otherwise it was giving me an error

File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

I also put

plt.imshow(im)
plt.show()

but it doesn’t work

please let me know how can I see the image on my ubuntu terminal using

python demo1.py

Matplotlib does not have a backend that produces images in a terminal. You need to have a windowing system available if you want to display plots interactively.

The Agg backend is not for display, but for saving to a file directly.

Additionally, Python 2 is end-of-life, so you really should stop using it.