. Advertisement .
..3..
. Advertisement .
..4..
I get an error
Traceback (most recent call last):
File "example.py", line 7, in <module>
plt.scatter(x, y, s=20)
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3241, in scatter
ax = gca()
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 928, in gca
return gcf().gca(**kwargs)
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 578, in gcf
return figure()
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 527, in figure
**kwargs)
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1810, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
when I try to run the following code:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(60)
y = np.random.randn(60)
plt.scatter(x, y, s=20)
out_png = 'path/to/store/out_file.png'
plt.savefig(out_png, dpi=150)
How to fix _tkinter.tclerror: no display name and no $display environment variable. Please give me some good ideas.
It was a problem I was having with Colab. The following code lines helped me to solve it. It should be at the top of your notebook.
This is the final answer. It works in different environments.
It wasn’t my intention to have it use the
Agg'
backend. I wanted it to only be used when it would go through Travis CI, for example.Matplotlib defaults to the Xwindows Backend. Matplotlib must be set to disable the Xwindows Backend This code should be added to the beginning of your script ( prior to importing Pyplot).
To use non-interactive backend, add
.config/matplotlib/matplotlibrc
line HTML12Oder, connect to server using
ssh -X remoteMachine
command. To use Xwindows You can also export displayexport DISPLAY=mymachine.com:0.0