From: Benjamin R. <ben...@ou...> - 2012-02-16 23:16:51
|
On Thursday, February 16, 2012, Martin Mokrejs wrote: > Hi Ben, > glad you found the answer. Once again, does F.get_size_inches() have to > return to > the user the numpy array? Why not a list or tuple? I don't mind matplotlib > internal > stuff. ;-) We don't return a list or a tuple because other functions within mpl needs the numpy array. > > In an answer to your proposed workaround > > > DefaultSize = tuple(F.get_size_inches()) > > let me comment that (I think) I tried also > > DefaultSize = F.get_size_inches()[:] > > but that also did not work for me. And was similarly think of the copy > module haven't > bothered to try that. ;-) > > You might want to read up on numpy arrays. A slice of an array returns a view. A slice on a view also returns a view. If you want a copy, the array has a copy() method. I don't know if the copy module would actually work because it would merely be copying the view (creating a duplicate view). Ben Root > > Yes, please document this at least if you really cannot return a simple > list or tuple. > Thanks, > Martin > > Benjamin Root wrote: > > > > > > On Thu, Feb 16, 2012 at 3:09 PM, Martin Mokrejs < > mmo...@fo... <javascript:;> <mailto: > mmo...@fo... <javascript:;>>> wrote: > > > > Hi Benjamin, > > thank you for you explanation. My comment is below in the text: > > > > Benjamin Root wrote: > > > > > > > > > On Tue, Feb 14, 2012 at 4:43 PM, Martin Mokrejs < > mmo...@fo... <mailto:mmo...@fo...> <mailto: > mmo...@fo... <mailto:mmo...@fo...>>> wrote: > > > > > > Ah, this seems to be the issue that my figsize was growing all > the time so it > > > went over the maximum limits. > > > > > > I thought this is valid: > > > DefaultSize = F.get_size_inches() > > > print str(DefaultSize) > > > blah > > > F.set_size_inches(DefaultSize) > > > > > > See http://matplotlib.sourceforge.net/api/figure_api.html > > > > > > <quote> > > > set_size_inches(*args, **kwargs) > > > > > > set_size_inches(w,h, forward=False) > > > > > > Set the figure size in inches > > > > > > Usage: > > > > > > fig.set_size_inches(w,h) # OR > > > fig.set_size_inches((w,h) ) > > > > > > optional kwarg forward=True will cause the canvas size to > be automatically updated; eg you can resize the figure window from the shell > > > > > > ACCEPTS: a w,h tuple with w,h in inches > > > </quote> > > > > > > Nope, it does not work. The print call gives me: [ 8. 6.]. > So, this is not a tuple? > > > Or python-2.7 issue how is it printed ... I fear? ;-) > > > Anyway, doing > > > > > > F.set_size_inches(11.2, 15) > > > > > > works for me. > > > > > > Martin > > > > > > > > > I am a little bit confused by your code example. You get the > figure size and print it, and *then* you set it with the exact same values, > and you are surprised that it came out as [8. 6.]? Note that the figure > size is stored internally as a numpy array, so when you do "print > str(DefaultSize)", you will get the string representation of the numpy > array. You can still pass in a tuple, list, or two separate elements. Try > this code: > > > > No, in my experience it did NOT work. I suspect F.set_size_inches() > either did not like the input tuple or something else. Now. after reading > your clarification, are you sure it can input the numpy array as well? What > I also tried was to re-set the figsize to original values. > > > > > > Yes, it can. I found the source of the problem, see further down. > > > > > > Ouch, I use pylab not matplotlib directly. :( > > > > > > Doesn't matter. > > > > > > $ python > > Python 2.7.2 (default, Feb 7 2012, 19:33:08) > > [GCC 4.5.3] on linux2 > > Type "help", "copyright", "credits" or "license" for more > information. > > >>> import pylab > > >>> F = pylab.gcf() > > >>> print F.get_size_inches() > > [ 8. 6.] > > >>> DefaultSize = F.get_size_inches() > > >>> print DefaultSize > > [ 8. 6.] > > >>> F.set_size_inches(10, 10) > > >>> print F.get_size_inches() > > [ 10. 10.] > > > |