Getting the shape manager through the OO interface in Matplotlib

I want to get the figure_manager of the created figure: for example, I can do this using the pyplot interface using:

from pylab import* figure() plot(arange(100)) mngr = get_current_fig_manager() 

However, if I have a few numbers:

 from pylab import * fig0 = figure() fig1 = figure() plot(arange(100)) mngr = fig0.get_manager() #DOES NOT WORK - no such method as Figure.get_manager() 

however, by carefully examining the drawing API, http://matplotlib.org/api/figure_api.html was not useful. My IDE also did not have autocomplete on the shape instance, none of the methods / members seemed to give me a "manager".

So, how do I do this and in general, where should I look, is there a pyplot method that I need an analog in the OO interface?

PS: what object does get_current_fig_manager () return anyway? In the debugger, I get:

 type(get_current_fig_manager()) <type 'instance'> 

which sounds pretty mysterious ...

+3
source share
1 answer
Good question. Your right, the documents do not say anything about the possibility of getting a manager or canvas. From code experience, the answer to your question is:
 >>> import matplotlib.pyplot as plt >>> a = plt.figure() >>> b = plt.figure() >>> a.canvas.manager <matplotlib.backends.backend_tkagg.FigureManagerTkAgg instance at 0x1c3e170> >>> b.canvas.manager <matplotlib.backends.backend_tkagg.FigureManagerTkAgg instance at 0x1c42ef0> 

The best place to find out about this is to read the code. In this case, I knew that I wanted to get the canvas so that I could get the figure manager, so I looked at the set_canvas method in figure.py and found the following code:

 def set_canvas(self, canvas): """ Set the canvas the contains the figure ACCEPTS: a FigureCanvas instance """ self.canvas = canvas 

From there (since there was no get_canvas method), I knew where the canvas was stored, and could access it directly.

NTN

+3
source

Source: https://habr.com/ru/post/910263/


All Articles