Bug with bbox_inches='tight' on Python 3

Hi everyone

I've found a few problems in the current matplotlib-py3 branch in the
_macosx.c code. I've put the fixes in a fork here:
  https://github.com/grahame/matplotlib-py3
I saw a pull request for a similar patch with a lot of comments that
seems to be stuck, so I thought I'd ask here what to do. It'd be great
to get the master branch working on Mac.

Another thing - I think I've found a str/bytes bug which I can't
figure it out. I've attached the code, if I run it on my machine I get
this output:

Traceback (most recent call last):
  File "crash.py", line 24, in <module>
    fig.canvas.print_figure(open('test.png', 'wb'), bbox_inches='tight')
  File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/backend_bases.py",
line 1951, in print_figure
    bbox_inches = self.figure.get_tightbbox(renderer)
  File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 1292, in get_tightbbox
    for ax in self.axes:
  File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 290, in _get_axes
    return self._axstack.as_list()
  File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in as_list
    ia_list = [a for k, a in self._elements]
  File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in <listcomp>
    ia_list = [a for k, a in self._elements]
TypeError: string argument expected, got 'bytes'

It's definitely something to do with the bbox_inches='tight' argument,
if I take that out everything works. Using the debugger I can't see
anything in any stack frame that explains the traceback - really odd!

Thanks
Grahame

crash.py (582 Bytes)

Hi everyone

I've found a few problems in the current matplotlib-py3 branch in the
_macosx.c code. I've put the fixes in a fork here:
   https://github.com/grahame/matplotlib-py3
I saw a pull request for a similar patch with a lot of comments that
seems to be stuck, so I thought I'd ask here what to do. It'd be great
to get the master branch working on Mac.

I was worried about accepting the changes without a Mac to test them on, and hoping that Michiel de Hoon (the Mac backend author) would have some comments. Maybe we can convince one of the other developers on this list who has a Mac to have a look.

Another thing - I think I've found a str/bytes bug which I can't
figure it out. I've attached the code, if I run it on my machine I get
this output:

Traceback (most recent call last):
   File "crash.py", line 24, in<module>
     fig.canvas.print_figure(open('test.png', 'wb'), bbox_inches='tight')
   File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/backend_bases.py",
line 1951, in print_figure
     bbox_inches = self.figure.get_tightbbox(renderer)
   File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 1292, in get_tightbbox
     for ax in self.axes:
   File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 290, in _get_axes
     return self._axstack.as_list()
   File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in as_list
     ia_list = [a for k, a in self._elements]
   File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in<listcomp>
     ia_list = [a for k, a in self._elements]
TypeError: string argument expected, got 'bytes'

It's definitely something to do with the bbox_inches='tight' argument,
if I take that out everything works. Using the debugger I can't see
anything in any stack frame that explains the traceback - really odd!

Can you file an issue for this in the matplotlib-py3 github project? I'm busy getting the matplotlib 1.1.x release finished up at the moment, and don't have a working environment for Python 3 right now. I'd hate for this bug to fall through the cracks.

Cheers,
Mike

···

On 08/24/2011 11:07 AM, Grahame Bowland wrote:

Indeed a confusing bug -- errors were not being returned correctly from the PNG extension.

Can you confirm that

https://github.com/matplotlib/matplotlib-py3/commit/927acf856bb321e22938846bb39f8b32d90172d4

resolves the issue?

Mike

···

On 08/24/2011 01:41 PM, Michael Droettboom wrote:

On 08/24/2011 11:07 AM, Grahame Bowland wrote:

Another thing - I think I've found a str/bytes bug which I can't
figure it out. I've attached the code, if I run it on my machine I get
this output:

Traceback (most recent call last):
    File "crash.py", line 24, in<module>
      fig.canvas.print_figure(open('test.png', 'wb'), bbox_inches='tight')
    File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/backend_bases.py",
line 1951, in print_figure
      bbox_inches = self.figure.get_tightbbox(renderer)
    File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 1292, in get_tightbbox
      for ax in self.axes:
    File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 290, in _get_axes
      return self._axstack.as_list()
    File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in as_list
      ia_list = [a for k, a in self._elements]
    File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in<listcomp>
      ia_list = [a for k, a in self._elements]
TypeError: string argument expected, got 'bytes'

It's definitely something to do with the bbox_inches='tight' argument,
if I take that out everything works. Using the debugger I can't see
anything in any stack frame that explains the traceback - really odd!

Can you file an issue for this in the matplotlib-py3 github project?
I'm busy getting the matplotlib 1.1.x release finished up at the moment,
and don't have a working environment for Python 3 right now. I'd hate
for this bug to fall through the cracks.

Hi Mike

Thanks very much, that solves the problem.

Cheers
Grahame

···

On 26 August 2011 01:38, Michael Droettboom <mdroe@...31...> wrote:

On 08/24/2011 01:41 PM, Michael Droettboom wrote:

On 08/24/2011 11:07 AM, Grahame Bowland wrote:

Another thing - I think I've found a str/bytes bug which I can't
figure it out. I've attached the code, if I run it on my machine I get
this output:

Traceback (most recent call last):
File "crash.py", line 24, in<module>
fig.canvas.print_figure(open('test.png', 'wb'), bbox_inches='tight')
File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/backend_bases.py",
line 1951, in print_figure
bbox_inches = self.figure.get_tightbbox(renderer)
File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 1292, in get_tightbbox
for ax in self.axes:
File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 290, in _get_axes
return self._axstack.as_list()
File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in as_list
ia_list = [a for k, a in self._elements]
File "/opt/shrubbery/lib/python3.2/site-packages/matplotlib/figure.py",
line 59, in<listcomp>
ia_list = [a for k, a in self._elements]
TypeError: string argument expected, got 'bytes'

It's definitely something to do with the bbox_inches='tight' argument,
if I take that out everything works. Using the debugger I can't see
anything in any stack frame that explains the traceback - really odd!

Can you file an issue for this in the matplotlib-py3 github project?
I'm busy getting the matplotlib 1.1.x release finished up at the moment,
and don't have a working environment for Python 3 right now. I'd hate
for this bug to fall through the cracks.

Indeed a confusing bug -- errors were not being returned correctly from
the PNG extension.

Can you confirm that

https://github.com/matplotlib/matplotlib-py3/commit/927acf856bb321e22938846bb39f8b32d90172d4

resolves the issue?