Matplotlib: how to set the current indicator?

This, hopefully, is a simple question, but I cannot figure it out at the moment. I want to use matplotlib to show 2 digits and then use them interactively. I create numbers with:

import matplotlib import pylab as pl f1 = pl.figure() f2 = pl.figure() 

and can use the MATLAB-like pyplot interface to build and draw both shapes. Via

 current_figure = pl.gcf() 

I can determine the current active digit for the pyplot interface, depending on which figure I clicked on. Now I want to draw something on the first digit with the pyplot interface, but the current digit can be any of them. So something like

 pl.set_current_figure(figure) 

or any workaround? (I know that I can use an object-oriented interface, but for interactive materials just using commands like plot (x, y) is much nicer)

+55
python matplotlib
Nov 02 '11 at 19:57
source share
2 answers

You can simply set the digit f1 as the new current digit with:

 pl.figure(f1.number) 

Another option is to give names (or numbers) to numbers that can help make the code more readable:

 pl.figure("Share values") # ... some plots ... pl.figure("Profits") # ... some plots ... pl.figure("Share values") # Selects the first figure again 

In fact, the digits of a β€œnumber” can be strings, which are perhaps more pronounced than prime numbers.

PS : the equivalent of the pylab.figure() gun is matplotlib.pyplot.figure() .

+55
Nov 02 '11 at
source share

Give each digit a number:

 f1 = pl.figure(1) f2 = pl.figure(2) # use f2 pl.figure(1) # make f1 active again 
+12
Nov 02 2018-11-11T00:
source share



All Articles