GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Issue with single contour level in contourf · Issue #138 · matplotlib/matplotlib

Issue with single contour level in contourf #138

New issue
Copy link
New issue
Copy link
Closed
Closed
Issue with single contour level in contourf#138
Copy link

Description

@astrofrog
astrofrog
opened on Jun 8, 2011
Issue body actions

The following code works:

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.contourf([[0.,1.], [1.,0.]], levels=[0.5, 1.0, 2.0])
fig.savefig('contourf.png')

but if I try and specify a single level, the code crashes:

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.contourf([[0.,1.], [1.,0.]], levels=[0.5])
fig.savefig('contourf.png')

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

Activity

  1. efiring commented on Jun 8, 2011

    @efiring
    efiring
    on Jun 8, 2011
    Member
    More actions

    On 06/08/2011 11:18 AM, astrofrog wrote:

    The following code works:

     import matplotlib as mpl
     mpl.use('Agg')
     import matplotlib.pyplot as plt
    
     fig = plt.figure()
     ax = fig.add_subplot(1, 1, 1)
     ax.contourf([[0.,1.], [1.,0.]], levels=[0.5, 1.0, 2.0])
     fig.savefig('contourf.png')
    

    but if I try and specify a single level, the code crashes:

     import matplotlib as mpl
     mpl.use('Agg')
     import matplotlib.pyplot as plt
    
     fig = plt.figure()
     ax = fig.add_subplot(1, 1, 1)
     ax.contourf([[0.,1.], [1.,0.]], levels=[0.5])
     fig.savefig('contourf.png')
    

    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
    
  2. astrofrog commented on Jun 8, 2011

    @astrofrog
    astrofrog
    on Jun 8, 2011
    ContributorAuthor
    More actions

    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.

  3. efiring commented on Jun 16, 2011

    @efiring
    efiring
    on Jun 16, 2011
    Member
    More actions

    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.

  4. efiring
    closed this as completedon Jun 16, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.