Skip to content

PcolorImage does not set _extent #8426

Closed
@Zaharid

Description

@Zaharid

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/formatters.py 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/pylabtools.py in <lambda>(fig)
    238 
    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/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    122 
    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/backend_bases.py 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/image.py in get_window_extent(self, renderer)
    704 
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions