Repository navigation
Closed
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesstatus: confirmed bug
Milestone
Description
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
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesstatus: confirmed bug
Activity
tacaswell commentedon Apr 4, 2017
For some reason
<matplotlib.image.PcolorImage object at 0x7f46ea157080>hasNoneas 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 thatPcolorImagedoes not have_exententproperly set.[-]hist2d fails sometimes when bins are not equally spaced.[/-][+]PcolorImage does not set `_extent`[/+]tacaswell commentedon Apr 4, 2017
Tagging as medium as this will require a fair amount of code tracing to sort out what is going on.
t-bltg commentedon Sep 20, 2017
Hitting this issue as well with mpl 2.1.0 (rc1), although a different test case (using a NonUniformImage) ...
workaround