Re: [Matplotlib-users] How to get a figure's number?

 Re: [Matplotlib-users] How to get a figure's number? From: John Hunter - 2005-03-18 21:21:59 ```>>>>> "Fernando" == Fernando Perez writes: Fernando> Hi all, I wonder how I can get, in an easy way, the Fernando> number of a figure returned by a call to figure(None). Fernando> The nasty way is: Fernando> allnums = [f.num for f in Fernando> _pylab_helpers.Gcf.get_all_fig_managers()] if allnums: Fernando> num = max(allnums) + 1 else: num = 1 Fernando> but this seems horrible for everyday, user-level code. Fernando> What I want to do is simply be able to make a call to: Fernando> ff=figure() Fernando> and then later make a series of plots which go to that Fernando> figure: Fernando> myplotfunc(fignum=ff.num) myplotfunc2(fignum=ff.num) ... What if we just attach the num attribute in the pylab figure function figManager.canvas.figure.num = num return figManager.canvas.figure ```

 [Matplotlib-users] How to get a figure's number? From: Fernando Perez - 2005-03-18 19:59:48 ```Hi all, I wonder how I can get, in an easy way, the number of a figure returned by a call to figure(None). The nasty way is: allnums = [f.num for f in _pylab_helpers.Gcf.get_all_fig_managers()] if allnums: num = max(allnums) + 1 else: num = 1 but this seems horrible for everyday, user-level code. What I want to do is simply be able to make a call to: ff=figure() and then later make a series of plots which go to that figure: myplotfunc(fignum=ff.num) myplotfunc2(fignum=ff.num) ... I need to overlay a set of plots on the same figures, and I don't want to manage manually the figure numbering. I'm comparing results across runs of a script, so the automatic figure(None) number increase is perfect. But I need a way to get a hold of those numbers somehow, and I don't see how. I looked at the attributes in the returned figure object, and I couldn't find the number anywhere (I think it's hidden higher up in the figure manager object). An alternate (perhaps more 'pythonic'?) solution would be to allow figure() to take figure objects (not just numbers) as arguments. In this case, it would simply be a matter of saying: ff=figure() and then later make a series of plots which go to that figure: myplotfunc(fig=ff) myplotfunc2(fig=ff) At any rate, either an integer-based or an object-based solution would work for me, so I'll be grateful for any pointers. best, f ```
 Re: [Matplotlib-users] How to get a figure's number? From: John Hunter - 2005-03-18 21:21:59 ```>>>>> "Fernando" == Fernando Perez writes: Fernando> Hi all, I wonder how I can get, in an easy way, the Fernando> number of a figure returned by a call to figure(None). Fernando> The nasty way is: Fernando> allnums = [f.num for f in Fernando> _pylab_helpers.Gcf.get_all_fig_managers()] if allnums: Fernando> num = max(allnums) + 1 else: num = 1 Fernando> but this seems horrible for everyday, user-level code. Fernando> What I want to do is simply be able to make a call to: Fernando> ff=figure() Fernando> and then later make a series of plots which go to that Fernando> figure: Fernando> myplotfunc(fignum=ff.num) myplotfunc2(fignum=ff.num) ... What if we just attach the num attribute in the pylab figure function figManager.canvas.figure.num = num return figManager.canvas.figure ```
 Re: [Matplotlib-users] How to get a figure's number? From: Fernando Perez - 2005-03-18 21:48:39 ```John Hunter wrote: >>>>>>"Fernando" == Fernando Perez writes: > > > Fernando> Hi all, I wonder how I can get, in an easy way, the > Fernando> number of a figure returned by a call to figure(None). > Fernando> The nasty way is: > > Fernando> allnums = [f.num for f in > Fernando> _pylab_helpers.Gcf.get_all_fig_managers()] if allnums: > Fernando> num = max(allnums) + 1 else: num = 1 > > Fernando> but this seems horrible for everyday, user-level code. > Fernando> What I want to do is simply be able to make a call to: > > Fernando> ff=figure() > > Fernando> and then later make a series of plots which go to that > Fernando> figure: > > Fernando> myplotfunc(fignum=ff.num) myplotfunc2(fignum=ff.num) ... > > What if we just attach the num attribute in the pylab figure function > > figManager.canvas.figure.num = num > return figManager.canvas.figure That's pretty much what I think would be the simplest solution, and I'd be happy with it. It would be nice if this little change made it into .73, along with removing this section from figure: if num==0: error_msg('Figure number can not be 0.\n' + \ 'Hey, give me a break, this is matlab(TM) compatability') return Best, f ```