Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:09:31+00:00 2026-06-07T07:09:31+00:00

I found that using matplotlib just to draw a diagram into a file is

  • 0

I found that using matplotlib just to draw a diagram into a file is not as easy as it seems from reading the tutorials.
In the tutorials it is explained, that you just accumulate the data and then:

import matplotlib.pyplot as plt
# ... fill variables with meaningful stuff
plt.plot(data.x,data.y,format_string)
plt.savefig(filename)

And done. That also works fine if you just execute it as a shell. But if you give this code to a process that doesn’t have any window (like jenkins), then you just get the following error:

Traceback (most recent call last):
  File "./to_graph.py", line 89, in <module>
    main()
  File "./to_graph.py", line 78, in main
    plt.plot(warnings[0],warnings[1],args.format_warnings,label="Warnings")
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2460, in plot
    ax = gca()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 701, in gca
    ax =  gcf().gca(**kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 369, in gcf
    return figure()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 343, in figure
    **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 80, in new_figure_manager
    window = Tk.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1688, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

The reason for this error, as I understand the sourcecode around the stack-trace lines, is that backend_tkagg.py expects to use an existing window (see the Tk.Tk() line in the stacktrace). So I wonder if there is a way to draw diagrams with matplotlib (or python at all) without relying on a window(-manager) to do the work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:09:33+00:00Added an answer on June 7, 2026 at 7:09 am

    You need to set a backend which will write directly to a file.

    For details, see :
    http://matplotlib.sourceforge.net/faq/usage_faq.html#what-is-a-backend

    You need to call matplotlib.use before importing pyplot.

    For instance :

    import matplotlib
    matplotlib.use("AGG")
    import pyplot
    # continue as usual
    

    Actually, I just found out that this is also the solution given in the documentation :

    http://matplotlib.sourceforge.net/faq/howto_faq.html#generate-images-without-having-a-window-appear

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found that you can't read from some sites using Python's urllib2(or urllib). An
I have found that creating a zip file using the Zip task provided by
I've found that there seems to be a problem using css transitions properties when
From googling around, I found that using while loops or using variables is discouraged.
I found that using Smarty with PHP, sometimes extra time will need to be
-o changes the output filename (I found that using --help) But I can't find
I have found that I have no problem using require to load something like
I am using a Java code that I found that generates a public and
I'm using read/write locks on Linux and I've found that trying to upgrade a
I've found that the admin of the server I'm using tends to leave python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.