Skip to content
  • Sponsor matplotlib/matplotlib

  • Notifications You must be signed in to change notification settings
  • Fork 7.9k

Imsave AssertionError (empty bboxes) #3802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2014
Merged

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Nov 17, 2014

Pyplot.imsave does not seem to work. The matplotlibrc file that I'm using: https://raw.githubusercontent.com/byuimpact/numerical_computing/develop/matplotlibrc

import matplotlib
matplotlib.rcParams = matplotlib.rc_params_from_file("./matplotlibrc")

import numpy as np
import matplotlib.pyplot as plt
f = np.random.randint(0, 255, shape=(92,92))
plt.imsave("test.png", f)

results in an AssertionError

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-23-02f5f5fccdfa> in <module>()
----> 1 plt.imsave("test.pdf", f)

/usr/lib/python2.7/site-packages/matplotlib/pyplot.pyc in imsave(*args, **kwargs)
   2218 @docstring.copy_dedent(_imsave)
   2219 def imsave(*args, **kwargs):
-> 2220     return _imsave(*args, **kwargs)
   2221 
   2222 

/usr/lib/python2.7/site-packages/matplotlib/image.pyc in imsave(fname, arr, vmin, vmax, cmap, format, origin, dpi)
   1312     canvas = FigureCanvas(fig)
   1313     im = fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
-> 1314     fig.savefig(fname, dpi=dpi, format=format, transparent=True)
   1315 
   1316 

/usr/lib/python2.7/site-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
   1468             self.set_frameon(frameon)
   1469 
-> 1470         self.canvas.print_figure(*args, **kwargs)
   1471 
   1472         if frameon:

/usr/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2141                     **kwargs)
   2142                 renderer = self.figure._cachedRenderer
-> 2143                 bbox_inches = self.figure.get_tightbbox(renderer)
   2144 
   2145                 bbox_artists = kwargs.pop("bbox_extra_artists", None)

/usr/lib/python2.7/site-packages/matplotlib/figure.pyc in get_tightbbox(self, renderer)
   1611                 bb.append(ax.get_tightbbox(renderer))
   1612 
-> 1613         _bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
   1614 
   1615         bbox_inches = TransformedBbox(_bbox,

/usr/lib/python2.7/site-packages/matplotlib/transforms.pyc in union(bboxes)
    720         Return a :class:`Bbox` that contains all of the given bboxes.
    721         """
--> 722         assert(len(bboxes))
    723 
    724         if len(bboxes) == 1:

AssertionError: 

It appears that the Bbox.union() results in an empty list.

EDIT: Gave the correct sample that code that produces the error.

@ayr0 ayr0 changed the title Imsave seems to be broken Imsave AssertionError (empty bboxes) Nov 15, 2014
@WeatherGod
Copy link
Member

Which version of matplotlib are you using?

On Sat, Nov 15, 2014 at 2:25 PM, Ryan notifications@github.com wrote:

Pyplot.imsave does not seem to work.

import numpy as npimport matplotlib.pyplot as plt
f = np.random.rand(0, 255, shape=(92,92))
plt.imsave("test.png", f)

results in an AssertionError


AssertionError Traceback (most recent call last)
in ()
----> 1 plt.imsave("test.pdf", f)

/usr/lib/python2.7/site-packages/matplotlib/pyplot.pyc in imsave(_args, *_kwargs)
2218 @docstring.copy_dedent(_imsave)
2219 def imsave(_args, *_kwargs):
-> 2220 return _imsave(_args, *_kwargs)
2221
2222

/usr/lib/python2.7/site-packages/matplotlib/image.pyc in imsave(fname, arr, vmin, vmax, cmap, format, origin, dpi)
1312 canvas = FigureCanvas(fig)
1313 im = fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
-> 1314 fig.savefig(fname, dpi=dpi, format=format, transparent=True)
1315
1316

/usr/lib/python2.7/site-packages/matplotlib/figure.pyc in savefig(self, _args, *_kwargs)
1468 self.set_frameon(frameon)
1469
-> 1470 self.canvas.print_figure(_args, *_kwargs)
1471
1472 if frameon:

/usr/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, *_kwargs)
2141 *_kwargs)
2142 renderer = self.figure._cachedRenderer
-> 2143 bbox_inches = self.figure.get_tightbbox(renderer)
2144
2145 bbox_artists = kwargs.pop("bbox_extra_artists", None)

/usr/lib/python2.7/site-packages/matplotlib/figure.pyc in get_tightbbox(self, renderer)
1611 bb.append(ax.get_tightbbox(renderer))
1612
-> 1613 _bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
1614
1615 bbox_inches = TransformedBbox(_bbox,

/usr/lib/python2.7/site-packages/matplotlib/transforms.pyc in union(bboxes)
720 Return a :class:Bbox that contains all of the given bboxes.
721 """
--> 722 assert(len(bboxes))
723
724 if len(bboxes) == 1:

AssertionError:

It appears that the Bbox.union() results in an empty list.
The matplotlibrc file that I'm using:
https://raw.githubusercontent.com/byuimpact/numerical_computing/develop/matplotlibrc


Reply to this email directly or view it on GitHub
#3802.

@ayr0
Copy link
Author

ayr0 commented Nov 15, 2014

My apologies. I'm using Matplotlib 1.4.2 on archlinux

@tacaswell
Copy link
Member

When I tried this example I had issues with generating the data (exceptions from numpy)

import numpy as np
import matplotlib.pyplot as plt
f = (np.random.rand(92,92)*255).astype('int')
plt.imsave("test.png", f)

works as expected. I suspect that you were passing an empty array to imsave which is what was blowing up.

In [15]: np.random.rand(0, 5)
Out[15]: array([], shape=(0, 5), dtype=float64)

This should probably fail more gracefully, but I don't think this is a bug.

@ayr0
Copy link
Author

ayr0 commented Nov 17, 2014

Sorry, my bad. I gave the wrong sample code. See the original post.

@mdboom
Copy link
Member

mdboom commented Nov 17, 2014

Again, I think there's an error in the example. randint has no argument shape -- I think you meant size. Once fixing that, I couldn't reproduce the crash. Which version of matplotlib are you running? Sorry -- I see above you're running 1.4.2.

@mdboom
Copy link
Member

mdboom commented Nov 17, 2014

PR attached.

tacaswell added a commit that referenced this pull request Nov 18, 2014
BUG : Imsave AssertionError (empty bboxes)
@tacaswell tacaswell merged commit 0202f3b into matplotlib:v1.4.x Nov 18, 2014
@mdboom mdboom deleted the issue3802 branch March 3, 2015 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants