• Register
0 votes
1.9k views

Problem :

I am learning Python. I have written a basic python script and trying to run the basic python script on the server:

import matplotlib.pyplot as plot
import numpy as nump

x = nump.random.randn(80)
y = nump.random.randn(80)

plot.scatter(x, y, s=30)

out_png = 'path/to/store/out_file.png'
plot.savefig(out_png, dpi=180)

I am trying to use a command python pyexample.py on this server which also has the matplotlib 1.5.1 installed on it but it fails with below 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

Why am I facing above error? How can I fix it?

8 4 2
2,300 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I had faced such issue earlier. To resolve the issue I just used below code at a very beginning of your python script. So it should be able to run smoothly on the different environments.

import os
import matplotlib as matpl
if os.environ.get('DISPLAY','') == '':
    print('Currently no display found. Using the non-interactive Agg backend')
    matpl.use('Agg')
import matplotlib.pyplot as plot

 It will fix your issue for sure.

5 2 1
4,980 points

Related questions

0 votes
1 answer 7 views
7 views
tclerror: no display name and no $display environment variable
asked Feb 16 ArifulIslam 7.5k points
1 vote
1 answer 735 views
735 views
Problem: I installed tkinter and I wrote this code to check if this works or not: import tkinter as tink a = tink.Tink() a.title('Total Seconds') button = tink.Button(a, text='Welcome', width=40, command=a.destroy) button.pack() a.mainloop() But after running this ... ", line 2, in <module> a = tink.Tink() AttributeError: module 'tkinter' has no attribute 'Tink' Can anyone help me to solve this?
asked Apr 29, 2020 samhaz 5k points
0 votes
1 answer 24 views
24 views
Problem Hello Kodlogs, What is a checkbox called in tkinter? I heard it is called checkButton if yes, how does it function. Can you please explain with a code example?
asked Oct 30, 2020 hashq 1.1k points
0 votes
1 answer 2K views
2K views
Problem : The import matplotlib.pyplot as plt is is giving me the error with python2.7, anaconda3. The error shown is as below: ImportError: libGL.so.1: cannot open shared object file: No such file or directory The Detailed Error report is as below : Traceback ... <module> from PyQt5 import QtCore, QtGui, QtWidgets ImportError: libGL.so.1: cannot open shared object file: No such file or directory
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 3.4K views
3.4K views
Problem : I am trying to make the rss reader using my tkinter library, and in one of the methods I am creating the text widget. It displays pretty fine until I try to add the scrollbars to it. Below is my code before the scrollbars: def txtcreate_text(tbxself, root): ... has slaves managed by grid on the line vertscroll.pack(side="right", fill="y", expand=False)" Any ideas how to fix above error?
asked Dec 21, 2019 alecxe 7.5k points
3 votes
1 answer 712 views
712 views
Problem: Hello guys, I am facing an issue while working with the class tkinter I&rsquo;ve recently shifted to the upgraded version of python from my older ones. After completed the upgrading the version I am trying to run my old projects. Here comes the wired part. My project ... 'tk' is not defined I have no idea what could be going on here. I am looking forward to having a solution. Thanks.
asked May 6, 2020 Gavin 15.3k points
0 votes
1 answer 14 views
14 views
Problem: I want to understand examples are included in the examples directory of the basemap source distribution. There are a number of Basemap instance methods for plotting data: I Want to understand these methods plotting in detail. contour(): draw contour lines. contourf(): ... for regular meshes). plot(): draw lines and/or markers. scatter(): draw points with markers. quiver(): draw vector
asked Jan 26 Mashhoodch 9.1k points
0 votes
1 answer 18 views
18 views
Problem: How can I put the text in the upper left (or upper right) corner of the matplotlib plot, such as where the top left legend will be, or on top of the plot but in the upper left corner? For example. if it is plt.scatter (), then something that is ... in the upper right corner. When positioning the legend type, it must not overlap with any points on the scatter plot in any case. Thank you!
asked Dec 30, 2020 sasha 8.4k points
0 votes
1 answer 1.7K views
1.7K views
Problem: I have recently installed opencv with all the dependencies. After the successful installation I have tried to import matplotlib for the very simple example. I have started facing below error when I only tried to install matplotlib via the pip with pip install ... linux-gnu.so' Consider using the `--user` option or check the permissions. How can I install matplotlib without any error?
asked Aug 26, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 62 views
62 views
Problem : I am new to python. I have tried to install below softwares: Python 2.5.4, Numpy 1.5.0 win32, Matplotlib 1.0.0 win32, pywin32 218. After doing so much of hard work I am still unable to plot the graphs in Python. I am facing ... > from matplotlib._path import affine_transform ImportError: DLL load failed: The specified module could not be found. Can somebody help me in fixing this error?
asked Feb 22, 2020 mphil 2.3k points