_RendererAgg(int(width), int(height), dpi, debug=False): ValueError: width and height must each be below 32768

Hi,
  the below code works for me but in case there are few values to be rendered
it chokes (I think this is the culprit or maybe one of the values isn't unique
in those input lists?):

    pylab.clf()
    if longlegends:
        F.set_size_inches( (DefaultSize[0], DefaultSize[1]*2.5) )

    _e = []
    _ee = []
    _eee = []
    for _name in _unique_names:
        _d = []
        for _i, _name2, _position in zip(range(len(_matching[1])), _matching[1], _matching[11]):
            if _name == _name2:
                _d.append(_matching[11][_i])
                _c = _colors_for_unique_names[_name]
                _l = _name
        if _d:
            _e.append(_d)
            _ee.append(_c)
            _eee.append(_l)

    if longlegends:
        pylab.subplot(211)
        params = {'legend.fontsize': 8}
        pylab.rcParams.update(params)

    pylab.hist(_e, bins=50, histtype='barstacked', align='mid', color=_ee, log=False, label=_eee)
    pylab.title("some title")
    pylab.xlabel("... position")
    pylab.ylabel("Occurrence ... (barstacked)")
    pylab.ylim(ymin=0)
    pylab.xlim(xmin=0, xmax=1200)
    if longlegends:
        pylab.legend(loc='upper left', bbox_to_anchor = (-0.15, -0.1), ncol=2)
        F.savefig(prefix + ".png", dpi=100)
    else:
        F.savefig(prefix + ".png", dpi=100)

    F.savefig(prefix + ".png", dpi=100)
  File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1172, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 2017, in print_figure
    **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 103, in print_png
    return agg.print_png(filename, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 445, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 400, in draw
    self.renderer = self.get_renderer()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 411, in get_renderer
    self.renderer = RendererAgg(w, h, self.figure.dpi)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 59, in __init__
    self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
ValueError: width and height must each be below 32768

  Could anybody make something out of the error message? I tried NOT to specify
bins=50 but that does not help. I have matplotlib-1.1.0. Thanks for any clues,
Martin
BTW: The ugly for loop I had to introduce because I could simply pass nested lists
with data values and color to pylab.hist().

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? :wink:
Anyway, doing

F.set_size_inches(11.2, 15)

works for me.

Martin

Martin Mokrejs wrote:

···

Hi,
  the below code works for me but in case there are few values to be rendered
it chokes (I think this is the culprit or maybe one of the values isn't unique
in those input lists?):

    pylab.clf()
    if longlegends:
        F.set_size_inches( (DefaultSize[0], DefaultSize[1]*2.5) )

    _e = []
    _ee = []
    _eee = []
    for _name in _unique_names:
        _d = []
        for _i, _name2, _position in zip(range(len(_matching[1])), _matching[1], _matching[11]):
            if _name == _name2:
                _d.append(_matching[11][_i])
                _c = _colors_for_unique_names[_name]
                _l = _name
        if _d:
            _e.append(_d)
            _ee.append(_c)
            _eee.append(_l)

    if longlegends:
        pylab.subplot(211)
        params = {'legend.fontsize': 8}
        pylab.rcParams.update(params)

    pylab.hist(_e, bins=50, histtype='barstacked', align='mid', color=_ee, log=False, label=_eee)
    pylab.title("some title")
    pylab.xlabel("... position")
    pylab.ylabel("Occurrence ... (barstacked)")
    pylab.ylim(ymin=0)
    pylab.xlim(xmin=0, xmax=1200)
    if longlegends:
        pylab.legend(loc='upper left', bbox_to_anchor = (-0.15, -0.1), ncol=2)
        F.savefig(prefix + ".png", dpi=100)
    else:
        F.savefig(prefix + ".png", dpi=100)

    F.savefig(prefix + ".png", dpi=100)
  File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1172, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 2017, in print_figure
    **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 103, in print_png
    return agg.print_png(filename, *args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 445, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 400, in draw
    self.renderer = self.get_renderer()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 411, in get_renderer
    self.renderer = RendererAgg(w, h, self.figure.dpi)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 59, in __init__
    self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
ValueError: width and height must each be below 32768

  Could anybody make something out of the error message? I tried NOT to specify
bins=50 but that does not help. I have matplotlib-1.1.0. Thanks for any clues,
Martin
BTW: The ugly for loop I had to introduce because I could simply pass nested lists
with data values and color to pylab.hist().

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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:

import matplotlib.pyplot as plt
fig = plt.figure()
print fig.get_size_inches()
fig.set_size_inches(11.2, 15.0)
print fig.get_size_inches()
fig.set_size_inches((4.0, 7.2))
print fig.get_size_inches()

fig.set_size_inches([9.3, 11.1])
print fig.get_size_inches()

You should see:

[ 8. 6.]
[ 11.2 15. ]
[ 4. 7.2]
[ 9.2 11.1]

Everything works as expected. There is nothing special about python 2.7 in this regard. Let us know if you are still having problems updating your figures and include a stand-alone example showing how the figure size is not being updated.

Cheers!
Ben Root

···

On Tue, Feb 14, 2012 at 4:43 PM, Martin Mokrejs <mmokrejs@…3951…> 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

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

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? :wink:

Anyway, doing

F.set_size_inches(11.2, 15)

works for me.

Martin

Hi Benjamin,
  thank you for you explanation. My comment is below in the text:

Benjamin Root 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? :wink:
    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.

Ouch, I use pylab not matplotlib directly. :frowning:

$ 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.]

F.set_size_inches(DefaultSize[0], DefaultSize[1])
print F.get_size_inches()

[ 10. 10.]

Why in the above example I cannot return back to figsize [ 8. 6.] ?

import matplotlib.pyplot as plt
fig = plt.figure()
print fig.get_size_inches()
fig.set_size_inches(11.2, 15.0)
print fig.get_size_inches()
fig.set_size_inches((4.0, 7.2))
print fig.get_size_inches()
fig.set_size_inches([9.3, 11.1])
print fig.get_size_inches()

You should see:

[ 8. 6.]
[ 11.2 15. ]
[ 4. 7.2]
[ 9.2 11.1]

Yes, this works.

Everything works as expected. There is nothing special about python 2.7 in this regard. Let us know if you are still having problems updating your figures and include a stand-alone example showing how the figure size is not being updated.

What does the internal numpy array representation bring good to the figsize? :wink:
Why don't you use a simple list/tuple? I am sure you know what you're doing,
am just curious. Especially if slicing behaves differently compared to list/tuple
and the .__str__() also gives in my eyes weird output. Sure, matter of taste. :wink:

Thanks,
Martin

···

On Tue, Feb 14, 2012 at 4:43 PM, Martin Mokrejs <mmokrejs@…3951… <mailto:mmokrejs@…3951…>> wrote:

Hi Benjamin,

thank you for you explanation. My comment is below in the text:

Benjamin Root 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](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. :frowning:

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.]

F.set_size_inches(DefaultSize[0], DefaultSize[1])

print F.get_size_inches()

[ 10. 10.]

The bug here is assuming that DefaultSize still contained the values you printed earlier. This is subtle (and I missed it before), but what you are getting back from F.get_size_inches() is a view of the internal numpy array. When you set the new size, the internal array was updated, not replaced. This is much in the same vein as Python mutables, but taken a bit further than you are probably used to. Because the internal array was updated, the view (stored in DefaultSize) showed the new data as well. So, when you tried to set (what you thought was still) the original size, it was merely setting the current values back to itself. Therefore, no change.

So, to force DefaultSize to be immutable, just cast it as a tuple:

DefaultSize = tuple(F.get_size_inches())

Why in the above example I cannot return back to figsize [ 8. 6.] ?

import matplotlib.pyplot as plt

fig = plt.figure()

print fig.get_size_inches()

fig.set_size_inches(11.2, 15.0)

print fig.get_size_inches()

fig.set_size_inches((4.0, 7.2))

print fig.get_size_inches()

fig.set_size_inches([9.3, 11.1])

print fig.get_size_inches()

You should see:

[ 8. 6.]

[ 11.2 15. ]

[ 4. 7.2]

[ 9.2 11.1]

Yes, this works.

Everything works as expected. There is nothing special about python 2.7 in this regard. Let us know if you are still having problems updating your figures and include a stand-alone example showing how the figure size is not being updated.

What does the internal numpy array representation bring good to the figsize? :wink:

Why don’t you use a simple list/tuple? I am sure you know what you’re doing,

am just curious. Especially if slicing behaves differently compared to list/tuple

and the .str() also gives in my eyes weird output. Sure, matter of taste. :wink:

We use numpy arrays internally for several reasons. Primarially is that we have to do mathematical operations with this information. list/tuple do not lend itself to that (which is why numpy exists in the first place). numpy arrays also enforce type checking (so you can’t put a string for a size value, or anything else that doesn’t make sense). Another reason is that the slicing is significantly more advanced than for list/tuples. Internally, there is a 2x2 array. I can slice in either dimension very easily, while a list of lists would not be easy. Lastly, we need a combination of the immutability of tuples (don’t want people changing the array size), but the mutability of lists (we want to be able to change the individual values).

I will admit that this issue is not immediately intuitive, and some documentation should probably be added to help prevent users like yourself from falling into this trap.

I hope that helps!
Ben Root

···

On Thu, Feb 16, 2012 at 3:09 PM, Martin Mokrejs <mmokrejs@…3951…> wrote:

On Tue, Feb 14, 2012 at 4:43 PM, Martin Mokrejs <mmokrejs@…3951… mailto:mmokrejs@...3951...> 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. :wink:

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. :wink:

  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 <mmokrejs@…3951… <mailto:mmokrejs@…3951…>> 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 <mmokrejs@…3951… <mailto:mmokrejs@…3951…> <mailto:mmokrejs@…3951…>> 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? :wink:
    > 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. :frowning:

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.]
    >>> F.set_size_inches(DefaultSize[0], DefaultSize[1])
    >>> print F.get_size_inches()
    [ 10. 10.]
    >>>

The bug here is assuming that DefaultSize still contained the values you printed earlier. This is subtle (and I missed it before), but what you are getting back from F.get_size_inches() is a view of the internal numpy array. When you set the new size, the internal array was updated, not replaced. This is much in the same vein as Python mutables, but taken a bit further than you are probably used to. Because the internal array was updated, the view (stored in DefaultSize) showed the new data as well. So, when you tried to set (what you thought was still) the original size, it was merely setting the current values back to itself. Therefore, no change.

So, to force DefaultSize to be immutable, just cast it as a tuple:

DefaultSize = tuple(F.get_size_inches())

    Why in the above example I cannot return back to figsize [ 8. 6.] ?

    >
    > import matplotlib.pyplot as plt
    > fig = plt.figure()
    > print fig.get_size_inches()
    > fig.set_size_inches(11.2, 15.0)
    > print fig.get_size_inches()
    > fig.set_size_inches((4.0, 7.2))
    > print fig.get_size_inches()
    > fig.set_size_inches([9.3, 11.1])
    > print fig.get_size_inches()
    >
    >
    > You should see:
    >
    > [ 8. 6.]
    > [ 11.2 15. ]
    > [ 4. 7.2]
    > [ 9.2 11.1]

    Yes, this works.

    >
    > Everything works as expected. There is nothing special about python 2.7 in this regard. Let us know if you are still having problems updating your figures and include a stand-alone example showing how the figure size is not being updated.

    What does the internal numpy array representation bring good to the figsize? :wink:
    Why don't you use a simple list/tuple? I am sure you know what you're doing,
    am just curious. Especially if slicing behaves differently compared to list/tuple
    and the .__str__() also gives in my eyes weird output. Sure, matter of taste. :wink:

We use numpy arrays internally for several reasons. Primarially is that we have to do mathematical operations with this information. list/tuple do not lend itself to that (which is why numpy exists in the first place). numpy arrays also enforce type checking (so you can't put a string for a size value, or anything else that doesn't make sense). Another reason is that the slicing is significantly more advanced than for list/tuples. Internally, there is a 2x2 array. I can slice in either dimension very easily, while a list of lists would not be easy. Lastly, we need a combination of the immutability of tuples (don't want people changing the array size), but the mutability of lists (we want to be able to change the individual values).

I will admit that this issue is not immediately intuitive, and some documentation should probably be added to help prevent users like yourself from falling into this trap.

I hope that helps!
Ben Root

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. :wink:

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. :wink:

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

···

On Thursday, February 16, 2012, Martin Mokrejs wrote:

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 <mmokrejs@…3951… mailto:mmokrejs@...3951...> 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 <mmokrejs@...3951... <mailto:mmokrejs@...3951...> <mailto:mmokrejs@...3951... <mailto:mmokrejs@...3951...>>> 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](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.]
>