Skip to content
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

PcolorImage does not set `_extent` #8426

Zaharid opened this issue Apr 4, 2017 · 3 comments


None yet
4 participants
Copy link

commented Apr 4, 2017

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

Bug summary

Creating a simple 2d histogram fails when the bins are not equally spaced under some circumstances.

Code for reproduction

  • A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required

On a Jupyter notebook

%matplotlib inline
import matplotlib.pyplot as plt
x = plt.hist2d([1,2,3], [3,5,6], bins=[[0,3,7], [1,2,3]])

Actual outcome

  • The output produced by the above code, which may be a screenshot, console output, etc.
TypeError                                 Traceback (most recent call last)
/home/zah/anaconda3/lib/python3.6/site-packages/IPython/core/ in __call__(self, obj)
    305                 pass
    306             else:
--> 307                 return printer(obj)
    308             # Finally look for special method names
    309             method = get_real_method(obj, self.print_method)

/home/zah/anaconda3/lib/python3.6/site-packages/IPython/core/ in <lambda>(fig)
    239     if 'png' in formats:
--> 240         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    241     if 'retina' in formats or 'png2x' in formats:
    242         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/home/zah/anaconda3/lib/python3.6/site-packages/IPython/core/ in print_figure(fig, fmt, bbox_inches, **kwargs)
    123     bytes_io = BytesIO()
--> 124     fig.canvas.print_figure(bytes_io, **kw)
    125     data = bytes_io.getvalue()
    126     if fmt == 'svg':

/home/zah/anaconda3/lib/python3.6/site-packages/matplotlib/ in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2200                 bbox_filtered = []
   2201                 for a in bbox_artists:
-> 2202                     bbox = a.get_window_extent(renderer)
   2203                     if a.get_clip_on():
   2204                         clip_box = a.get_clip_box()

/home/zah/anaconda3/lib/python3.6/site-packages/matplotlib/ in get_window_extent(self, renderer)
    705     def get_window_extent(self, renderer=None):
--> 706         x0, x1, y0, y1 = self._extent
    707         bbox = Bbox.from_extents([x0, y0, x1, y1])
    708         return bbox.transformed(self.axes.transData)

TypeError: 'NoneType' object is not iterable

<matplotlib.figure.Figure at 0x7f828c153240>

This works if I remove the %matplotlib inline above, even if I try to write a png image with e.g. plt.savefig('/tmp/xx.png'). However the bug was found in a code that doesn't use IPython (though I don't know how to reproduce it).

It does work if I change the histogram to:

x = plt.hist2d([1,2,3], [3,5,6], bins=[[0,3,6], [1,2,3]])

making all the bins equally spaced.

Expected outcome

  • No crash.

I'm using the conda forge package of mpl 2.0.


This comment has been minimized.

Copy link

commented Apr 4, 2017

For some reason <matplotlib.image.PcolorImage object at 0x7f46ea157080> has None as it's extent. This is blowing up when the bbox_inches tight tries to sort out how big it is, but the underlying issue is that PcolorImage does not have _exentent properly set.

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Apr 4, 2017

@tacaswell tacaswell changed the title hist2d fails sometimes when bins are not equally spaced. PcolorImage does not set `_extent` Apr 4, 2017


This comment has been minimized.

Copy link

commented Apr 4, 2017

Tagging as medium as this will require a fair amount of code tracing to sort out what is going on.

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017


This comment has been minimized.

Copy link

commented Sep 20, 2017

Hitting this issue as well with mpl 2.1.0 (rc1), although a different test case (using a NonUniformImage) ...

import pylab as plt
x = plt.hist2d([1,2,3], [3,5,6], bins=[[0,3,7], [1,2,3]])
im = x[-1]

print(im.get_window_extent())   # <= throws TypeError: 'NoneType' object is not iterable


import pylab as plt
x = plt.hist2d([1,2,3], [3,5,6], bins=[[0,3,7], [1,2,3]])
im = x[-1]

im.set_extent(im.get_extent())  # <= workaround
print(im.get_window_extent())  # no issue

@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017

@AtharvaKhare AtharvaKhare referenced this issue Oct 16, 2017


BUG: Fix `_extent` not set in PcolorImage #9442

2 of 6 tasks complete

@QuLogic QuLogic modified the milestones: v2.2, v2.1.1 Oct 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.