When I execute
#!/usr/bin/env python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.show()
(and more complex examples) I get
/usr/local/lib/python3.4/dist-packages/
matplotlib/backends/backend_gtk3.py:215: Warning:
Source ID 7 was not found when attempting to remove it
GLib.source_remove(self._idle_event_id)
What causes this and how can I get rid of these warnings?
I know that I can use
import warnings
warnings.simplefilter("ignore")
to get rid of all warnings, but that is not what I am asking for. I want to have warnings, but none from matplotlib (especially the one from above).
GLib.source_remove
was not successful because the self.close_event()
that was executed before probably already did the job.
This commit should fix your problem. It is from the 23rd February. You can either wait for the next release or apply the patch manually.
Use plt.close()
to fix this issue.
Sorry in advance for answering an old question but I came across a similar issue after installing Python 3.6.9 and matplotlib
via pip
on a machine running with a Linux distro. My intent was to be able to re-run old scripts which involved pyplot
after upgrading Python on said machine. While the scripts ran until completion and provided the expected output, I was always getting this warning:
/home/jefgrailet/.local/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py:195: Warning: Source ID 8 was not found when attempting to remove it
GLib.source_remove(self._idle_draw_id)
upon using the savefig()
method from pyplot
(I guess a similar problem would have occurred with the show()
method as well). The line mentioned in the warning corresponds to this method found in backend_gtk3.py
:
def destroy(self):
#Gtk.DrawingArea.destroy(self)
self.close_event()
if self._idle_draw_id != 0:
GLib.source_remove(self._idle_draw_id)
I looked up on the matplotlib GitHub to check if there was a more recent version of the same script or if this problem was known, and it turns out the current implementation of the method above only rely on the self.close_event()
instruction, i.e., the GLib.source_remove()
is unnecessary.
Therefore, I commented the last 2 lines in the code above and saved the changes. After making this edit, I could run my scripts without getting any warning. I hope this will help people encountering a similar problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With