Traceback (most recent call last):
File "test.py", line 7, in <module>
ax.contourf([[0.,1.], [1.,0.]], levels=[0.5])
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/axes.py", line 7403, in contourf
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 1103, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 719, in __init__
self.allsegs, self.allkinds = self._get_allsegs_and_allkinds()
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 1136, in _get_allsegs_and_allkinds
lowers, uppers = self._get_lowers_and_uppers()
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 820, in _get_lowers_and_uppers
if self.zmin == lowers[0]:
IndexError: index out of bounds
contourf contours between levels, so there is not much it can do with
a single level. The error (an invalid input) could be trapped at an
early stage. That sort of input validation is done somewhat erratically
in mpl. Personally, I don't want to see us try to anticipate every
possible input error and clutter the code with validation, but some
types of error are worth trapping.
Eric
The exception is:
Traceback (most recent call last):
File "test.py", line 7, in<module>
ax.contourf([[0.,1.], [1.,0.]], levels=[0.5])
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/axes.py", line 7403, in contourf
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 1103, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 719, in __init__
self.allsegs, self.allkinds = self._get_allsegs_and_allkinds()
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 1136, in _get_allsegs_and_allkinds
lowers, uppers = self._get_lowers_and_uppers()
File "/Users/tom/Library/Python/2.6/site-packages/matplotlib/contour.py", line 820, in _get_lowers_and_uppers
if self.zmin == lowers[0]:
IndexError: index out of bounds
Ok, that makes sense. One possibility would be that if the length of the levels iterable is 1, one could append +inf as the second value (since that is probably the expected behavior if people try and specify a single value). Just a thought, but feel free to close the ticket without any changes.
Closed with 58c4713. It turns out that a check for 2 or more levels for contourf was already being made, but it was missing the case where the levels were specified via a kwarg. I slight rearrangement fixed that.
Activity
efiring commented on Jun 8, 2011
On 06/08/2011 11:18 AM, astrofrog wrote:
contourf contours between levels, so there is not much it can do with
a single level. The error (an invalid input) could be trapped at an
early stage. That sort of input validation is done somewhat erratically
in mpl. Personally, I don't want to see us try to anticipate every
possible input error and clutter the code with validation, but some
types of error are worth trapping.
Eric
astrofrog commented on Jun 8, 2011
Ok, that makes sense. One possibility would be that if the length of the levels iterable is 1, one could append +inf as the second value (since that is probably the expected behavior if people try and specify a single value). Just a thought, but feel free to close the ticket without any changes.
efiring commented on Jun 16, 2011
Closed with 58c4713. It turns out that a check for 2 or more levels for contourf was already being made, but it was missing the case where the levels were specified via a kwarg. I slight rearrangement fixed that.