Tkagg backend prints backtrace in some circumstances · Issue #20204 · matplotlib/matplotlib · GitHub
Skip to content

Tkagg backend prints backtrace in some circumstances #20204

Description

@MJKirk

Bug report

When using the tkagg backend, a backtrace gets printed, although it doesn't stop and the script finishes normally.
It only seems to happen if you save a figure to a PDF, and then save to a PNG with the bbox_inches="tight" option.
Doing just PNG with tight bbox, or PDF then PNG without tight bbox doesn't output the backtrace.

Code for reproduction

import matplotlib
print("Backend = ", matplotlib.get_backend())
import matplotlib.pyplot as plt
plt.plot((1,2),(3,4))
print("savefig to PDF")
plt.savefig("fig.pdf")
print("savefig to PNG")
plt.savefig("fig.png", bbox_inches="tight")
print("Done")

Actual outcome

Backend =  TkAgg
savefig to PDF
savefig to PNG
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 749, in callit
    func(*args)
  File "/home/kirkmatt/tktest/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 253, in idle_draw
    self.draw()
  File "/home/kirkmatt/tktest/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File "/home/kirkmatt/tktest/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 407, in draw
    self.figure.draw(self.renderer)
  File "/home/kirkmatt/tktest/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 1544, in _draw
    def _draw(renderer): raise Done(renderer)
matplotlib.backend_bases._get_renderer.<locals>.Done: <matplotlib.backends.backend_agg.RendererAgg object at 0x7f019bb6b5c0>
Done

Expected outcome
The exception is caught somewhere and no backtrace is printed.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.3.4
  • Matplotlib backend: TkAgg
  • Python version: 3.6.9
  • Other libraries: Tkinter installed using apt install python3-tk, matplotlib installed in a virtualenv with pip

This is possibly related to #18186
There's also a stackoverflow question, although in that case they just save to a png and get the traceback, while if I am only saving to PNG I don't.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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