Skip to content

Tkagg backend prints backtrace in some circumstances #20204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MJKirk opened this issue May 11, 2021 · 2 comments
Closed

Tkagg backend prints backtrace in some circumstances #20204

MJKirk opened this issue May 11, 2021 · 2 comments
Labels
Milestone

Comments

@MJKirk
Copy link

MJKirk commented May 11, 2021

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.

@jklymak
Copy link
Member

jklymak commented May 11, 2021

@anntzer this seems related to #14134?

@jklymak jklymak added this to the v3.4.3 milestone May 11, 2021
@anntzer
Copy link
Contributor

anntzer commented May 11, 2021

I can repro on 3.3.4 but that's fixed on master (since 8a8786f).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants