Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pyplot.savefig() throwing warning suggesting a bug (possibly in figManger) #17507

@MetalGearBronya

Description

@MetalGearBronya

Bug report

Bug summary

When using pyplot, pyplot.savefig() throws a warning which is non-existent with figure.Figure.savefig(). Upon understanding the warning message and some investigation, it should be associated with figManager adding duplicate "sources of save" to Glib when saving "the current figure" (i.e. it does not recongize the figure being saved is the same as current figure. )

This is important as plt.savefig() is usually the way to go when using the matlab style plotting provided by pyplot package. Currently, using plt.gcf().savefig('1.png') would make this error go away, but that's using the object-oriented style of coding, which would require a change in ways of thinking and hence may cause confusion.

Suggestion: add a check of the internal figure id in pyplot.savefig() would prevent any duplicates from being generated.

Code for reproduction

import matplotlib.pyplot as plt

plt.figure()
plt.plot([1, 2, 3])
plt.savefig('1.png')

Actual outcome

This shows up in the terminal

/usr/local/lib/python3.8/dist-packages/matplotlib/backends/backend_gtk3.py:195: Warning: Source ID 4 was not found when attempting to remove it
  GLib.source_remove(self._idle_draw_id)

Expected outcome

No warning should be thrown.

Matplotlib version

  • Operating system: Ubuntu 20.04
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): GTK3Agg
  • Python version: 3.8.2

matplotlib was installed via pip3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions