Repository navigation
Description
In my AWS Ubuntu 14.02 instance I installed the matplotlib dependencies and then via pip I installed matplotlib:
sudo apt-get build-dep python-matplotlib
sudo pip install matplotlib
sudo pip freeze:
matplotlib==1.4.0
in a brand new file plotting1.py I wrote:
!/usr/bin/python
from pylab import *
plot([1,2,3])
show()
after typying chmod +x plotting1.py, I executed the little script:
time python plotting1.py
Traceback (most recent call last):
File "plotting1.py", line 4, in
plot([1,2,3])
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3086, in plot
ax = gca()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 827, in gca
ax = gcf().gca(*_kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 461, in gcf
return figure()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 434, in figure
*_kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 47, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 54, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 72, in init
FigureCanvasQT.init(self, figure)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4.p y", line 68, in init
_create_qApp()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.p y", line 139, in _create_qApp
raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable
real 0m0.404s
user 0m0.284s
What do I have to do now?
Looking forward to your kind help.
Kind regards.
Marco
Activity
cimarronm commentedon Sep 4, 2014
Do you have the X server running? What is your DISPLAY environment variable set to (
echo $DISPLAY)?marcoippolito commentedon Sep 4, 2014
Hi,
thanks for helping!!!!
echo $DISPLAY
so it say nothing
What do I have to do to make X server running in my AWS Ubuntu 12.04 instance?
I rebooted but still nothing:
echo $DISPLAY
Do you know how to set the DISPLAY environment variable to disp?
marcoippolito commentedon Sep 4, 2014
Solved. I cannot visualize graphs on AWS server.
so I have to save them in files and download them locally.
Thanks for your kind help.
Kind regards.
Marco
LinZichuan commentedon Mar 13, 2016
I had the same problem and I solved it by adding
plt.switch_backend('agg')afterimport matplotlib.pyplot as pltamberkaka commentedon Apr 22, 2016
@LinZichuan I encoutered this problem too and your solution works. Thanks for your sharing!
jenshnielsen commentedon Apr 23, 2016
For the record it's better to chose a backend before importing pyplot i.e.
aluenkinglee commentedon Jan 3, 2017
@LinZichuan Great! It works
bzhr commentedon Jan 5, 2017
For me on AWS ec2 instance
import matplotlib matplotlib.use('agg')Does not work. But
plt.switch_backend('agg')does the trick.
hana9090 commentedon Apr 1, 2017
@jenshnielsen
I have this error, although I add
hana9090 commentedon Apr 1, 2017
@bzhr
I have modified as you suggested, by replacing
pltwithplt.switch_backend('agg')I have the following error:
tacaswell commentedon Apr 2, 2017
@hana9090 That is not how the library works.
plt.switch_backend()changes some global state which affects how future calls toplt.subplots()works.teuneboon commentedon Jul 24, 2017
For others having this issue: for me it was solved by putting the
all the way at the top of the file it was used in. Initially I though "hmm, it should be fine as long as I put it above all other matplotlib stuff", but nope! It had to be all the way on the top for it to work.
tacaswell commentedon Jul 24, 2017
@teuneboon It must be above anything that imports pyplot.
Use switch_backend instead, see matplotlib/matplotlib#3466
3 remaining items
WeatherGod commentedon Nov 17, 2017
sulth commentedon Nov 18, 2017
Hi Thanks !i got it.it was due to agg (non interactive visualisation env).replaced it with qt4agg (interactive)and it worked
Use plt.switch_backend
XiangyunHuang commentedon Apr 16, 2018
That works for me in R Markdown
Naman-ntc commentedon May 22, 2018
Is there any other method where matplotlib plots and shows over ssh or manually saving is the only option??
WeatherGod commentedon May 22, 2018
Declare a backend for matplotlib
Declare a backend for matplotlib (#171)
kapil-varshney commentedon Aug 6, 2018
^ Solved the problem for me. Thanks @jenshnielsen .
Use plt.switch_backend
debovis commentedon May 13, 2019
Switching to 'agg' does solve the issue. Although I am back stuck at this issue: #12074
Working on sumsims, incrementing version.
Use plt.switch_backend
Use plt.switch_backend
Use plt.switch_backend