Skip to content
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

Show fails on figures created with the object-oriented system #1219

Closed
jenshnielsen opened this issue Sep 8, 2012 · 6 comments · Fixed by #1220 or #14568
Closed

Show fails on figures created with the object-oriented system #1219

jenshnielsen opened this issue Sep 8, 2012 · 6 comments · Fixed by #1220 or #14568
Milestone

Comments

@jenshnielsen
Copy link
Member

The following code fails with a:

AttributeError: 'FigureCanvasTkAgg' object has no attribute 'manager'

On all all gui backends that I have tested. This seems to be because non of the canvases in any backends
have a manager attribute which is requested in the show method of the figure at line 348 in figure.py.

import matplotlib
matplotlib.use('gtkagg')
import matplotlib.backends as mbackends  # lazy import
from matplotlib.figure import Figure
fig = Figure()
ax = fig.add_subplot(1,1,1)
ax.plot(range(10))
fig.show()
@efiring
Copy link
Member

efiring commented Sep 8, 2012

Thank you, I see where this is happening. I'm not sure yet whether this is a problem with a single changeset, or whether it is an interaction between 2 or more. I will look into it now.

@efiring
Copy link
Member

efiring commented Sep 8, 2012

I have some more investigation to do as to how to handle this, but my first thought is that Figure.show() was never intended to be used with a figure created outside the pyplot paradigm; it was monkey-patched in by the gui backends to be used in the pyplot context. Now that it is exposed explicitly in the Figure API, it is natural to expect it to work without pyplot--but it doesn't, because it was not designed to do so. One solution would be to make this clear in the docstring and in the exception generated when it is called on an unmanaged figure. I will do this if I can't think of anything better.

@sleepyhollo
Copy link

I get the same error.

Using:

  • Windows 10; 64 bit
  • Python 3.7.3 (64 bit)
  • Matplotlib 3.1.0
  • Tkinter 8.6

Steps to replicate:

  1. the sample code for embedding Matplotlib in Tkinter as described here,
  2. Moving or zoom the figure
  3. After that, move the mouse on the figure
  4. The console floods with AttributeError: 'FigureCanvasTkAgg' object has no attribute 'manager'.

@abinitial
Copy link

HAHAHA, I get a quite funny solution. Define a empty class like , and assign it a attribute window=None. Then write like this:
toolbar = NavigationToolbar2Tk(canvas, root)
canvas.manager = OOO()
canvas.manager.window = toolbar.window

@MichaMEG
Copy link

MichaMEG commented Nov 1, 2021

I get the same error.

Using: Debian 10 and 11 + normal python3, python3-matplotlib, ... from Debian 10 and 11
I have now unfortunately not understood how to solve the problem!?
Could someone here explain to a poor troll what I need to change. Thank you very much ;)

My code:

import psycopg2, psycopg2.extras
import matplotlib
matplotlib.use('Agg') # => non-GUI backend
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import numpy as np
import os
import sys
from time import gmtime, strftime
matplotlib.rcParams['timezone'] = strftime("%z", gmtime())
# blabla ...
plt.show()
plotfile = path + "plot_seismic_sensor_%s" %nr + "." + file_ending
fig.savefig(plotfile, bbox_inches='tight')
# blabla ....

@jklymak
Copy link
Member

jklymak commented Nov 1, 2021

Please open a new issue that has a self-contained minimal example (if the problem persists after you create the example).

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