Skip to content

pcolor does not handle non-array C data #5205

Closed

Description

@tacaswell

reported via VisTrails/VisTrails#1132

may be a regression from 1.3 series, reported against 1.4.3, verified against master. Not sure what last version it work on was.

import matplotlib.pyplot as plt
import numpy as np

def func3(x, ):
    return (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)


# make these smaller to increase the resolution
dx, dy = 0.05, 0.05

x = np.arange(-3.0, 3.0001, dx)
y = np.arange(-3.0, 3.0001, dy)
X, Y = np.meshgrid(x, y)

Z = func3(X, Y)

# fails
plt.pcolor(X, Y, list(Z))
# plt.pcolor(X, Y, Z)  # works

Activity

  1. added
    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Oct 7, 2015
  2. added this to the milestone on Oct 7, 2015
  3. WeatherGod commented on Oct 7, 2015

    @WeatherGod
    Member

    Problem is in lib/matplotlib/axes/_axes.py:4969 in _pcolorargs(). It
    assumes that the C argument has the .shape attribute.

            if len(args) == 1:
                C = args[0]
                numRows, numCols = C.shape
                if allmatch:
                    X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
                else:
                    X, Y = np.meshgrid(np.arange(numCols + 1),
                                       np.arange(numRows + 1))
                return X, Y, C
    
            if len(args) == 3:
                X, Y, C = args
                numRows, numCols = C.shape
            else:
                raise TypeError(
                    'Illegal arguments to %s; see help(%s)' % (funcname,
    funcname))
    

    Should be pretty straight-forward to just slap on a C = np.asanyarray(C)
    before trying to access its shape.

    On Wed, Oct 7, 2015 at 2:26 PM, Thomas A Caswell notifications@github.com
    wrote:

    reported via VisTrails/VisTrails#1132
    VisTrails/VisTrails#1132

    may be a regression from 1.3 series.

    import matplotlib.pyplot as pltimport numpy as np
    def func3(x, ):
    return (1 - x/2 + x5 + y3) * np.exp(-x2 - y2)

    make these smaller to increase the resolution

    dx, dy = 0.05, 0.05

    x = np.arange(-3.0, 3.0001, dx)
    y = np.arange(-3.0, 3.0001, dy)
    X, Y = np.meshgrid(x, y)

    Z = func3(X, Y)

    fails

    plt.pcolor(X, Y, list(Z))# plt.pcolor(X, Y, Z) # works

    —
    Reply to this email directly or view it on GitHub
    #5205.

  4. WeatherGod commented on Oct 7, 2015

    @WeatherGod
    Member

    We might need to do something similar for X and Y, but I know that might
    have issues with units. Didn't @dopplershift come up with a cbook function
    that is like asanyarray, but safer?

    On Wed, Oct 7, 2015 at 2:35 PM, Benjamin Root ben.v.root@gmail.com wrote:

    Problem is in lib/matplotlib/axes/_axes.py:4969 in _pcolorargs(). It
    assumes that the C argument has the .shape attribute.

            if len(args) == 1:
                C = args[0]
                numRows, numCols = C.shape
                if allmatch:
                    X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
                else:
                    X, Y = np.meshgrid(np.arange(numCols + 1),
                                       np.arange(numRows + 1))
                return X, Y, C
    
            if len(args) == 3:
                X, Y, C = args
                numRows, numCols = C.shape
            else:
                raise TypeError(
                    'Illegal arguments to %s; see help(%s)' % (funcname,
    funcname))
    

    Should be pretty straight-forward to just slap on a C = np.asanyarray(C)
    before trying to access its shape.

    On Wed, Oct 7, 2015 at 2:26 PM, Thomas A Caswell <notifications@github.com

    wrote:

    reported via VisTrails/VisTrails#1132
    VisTrails/VisTrails#1132

    may be a regression from 1.3 series.

    import matplotlib.pyplot as pltimport numpy as np
    def func3(x, ):
    return (1 - x/2 + x5 + y3) * np.exp(-x2 - y2)

    make these smaller to increase the resolution

    dx, dy = 0.05, 0.05

    x = np.arange(-3.0, 3.0001, dx)
    y = np.arange(-3.0, 3.0001, dy)
    X, Y = np.meshgrid(x, y)

    Z = func3(X, Y)

    fails

    plt.pcolor(X, Y, list(Z))# plt.pcolor(X, Y, Z) # works

    —
    Reply to this email directly or view it on GitHub
    #5205.

  5. dopplershift commented on Oct 7, 2015

    @dopplershift
    Contributor

    I made a stand-in for atleast_1d(), since it doesn't preserve subclasses; asanyarray() doesn't have that problem.

  6. efiring commented on Oct 7, 2015

    @efiring
    Member

    fails

    plt.pcolor(X, Y,list(Z))

    I don't see why one should expect the above to work. Pcolor and
    similar functions are in displaying 2-D, so Z fundamentally has to be 2-D.

    I would close this as not a bug.

    plt.pcolor(X, Y, Z) # works

  7. WeatherGod commented on Oct 7, 2015

    @WeatherGod
    Member

    @efiring, it is a list of 1-D numpy arrays. Applying asanyarray() would
    convert it into a 2D numpy array. I am just about done with a PR to fix
    this.

    On Wed, Oct 7, 2015 at 2:50 PM, Eric Firing notifications@github.com
    wrote:

    fails

    plt.pcolor(X, Y,list(Z))

    I don't see why one should expect the above to work. Pcolor and
    similar functions are in displaying 2-D, so Z fundamentally has to be 2-D.

    I would close this as not a bug.

    plt.pcolor(X, Y, Z) # works

    —
    Reply to this email directly or view it on GitHub
    #5205 (comment)
    .

  8. QuLogic commented on Dec 3, 2015

    @QuLogic
    Member

    Fixed by #5206, I think.

  9. modified the milestones: v1.5.1, on Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions