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

  • Home
  • SEARCH
  • 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 8306617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:22:04+00:00 2026-06-08T18:22:04+00:00

I ran into a python error that i have been trying to solve for

  • 0

I ran into a python error that i have been trying to solve for several days now.
My program creates figures, saves and closes them which works fine except for this error. Usually it does not hinder the saving process but sometimes a picture is missing the lower part when saved. The odd thing is that this only happens every second time the loop reaches the savefig method, here is my code:

for num in np.arange(file_number):
    plt.figure('abc' + str(num),figsize=(22,12),dpi=100)
    #some plots are added to the figure
    print 1
    plt.savefig(os.path.join(savepath,filename),dpi=100)
    print 2
    plt.close()                                                                    
    print 3

I use the print commands to see where the error occurs. Here is the console output of spyder:

Reading file1.file
1
2
3
Reading file2.file
1
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_qt4.py", line 151, in <lambda>
    lambda: self.close_event())
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1564, in close_event
    self.callbacks.process(s, event)
RuntimeError: underlying C/C++ object has been deleted
2
3
Reading file3.file
1
2
3
Reading file4.file
1
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_qt4.py", line 151, in <lambda>
    lambda: self.close_event())
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1564, in close_event
    self.callbacks.process(s, event)
RuntimeError: underlying C/C++ object has been deleted
2
3

To my understanding, the error already occurs while saving the figure (every second time), although it works fine if i omit the close() command. In that case, my RAM is filled after about 70 files and sometimes i need to evaluate a couple of hundreds. That’s why i need to include the close() command or something similar.
If you solve this (or improve my programing, i guess the way i did this saving and closing might be considered ugly) please help me.

  • 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-08T18:22:05+00:00Added an answer on June 8, 2026 at 6:22 pm

    How about change the backend to other options? For example:

    import matplotlib as mpl
    mpl.use( "agg" )
    
    from matplotlib import pyplot as plt
    import numpy as np
    
    print plt.get_backend()
    
    file_number = 100
    for num in np.arange(file_number):
        plt.figure('abc' + str(num),figsize=(22,12),dpi=100)
        #some plots are added to the figure
        print 1
        plt.savefig("%d.png" % num,dpi=100)
        print 2
        plt.close()
        print 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many problems I've ran into in Python have been related to not having something
I ran into unbound method error in python with this code: import random class
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
Ran into this error message while trying to select some records off a table.
I have started to play around with boost python a bit and ran into
I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
I ran into an interesting problem. I have a MySQL database that contains some
I have a completely non-interactive python program that takes some command-line options and input
i've ran into this wierd error since few days where most of the applications/frameworks/modules
I'm new in python, and just ran into this statement data = dict( (k,

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.