Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcolor does not handle non-array C data #5205

Closed
tacaswell opened this issue Oct 7, 2015 · 6 comments
Closed

pcolor does not handle non-array C data #5205

tacaswell opened this issue Oct 7, 2015 · 6 comments
Assignees
Labels
API: consistency Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Milestone

Comments

@tacaswell
Copy link
Member

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
@tacaswell tacaswell added API: consistency Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Oct 7, 2015
@tacaswell tacaswell added this to the next bug fix release (2.0.1) milestone Oct 7, 2015
@WeatherGod
Copy link
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.

@WeatherGod
Copy link
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.

@dopplershift
Copy link
Contributor

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

@efiring
Copy link
Member

efiring commented Oct 7, 2015

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

@WeatherGod
Copy link
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)
.

@QuLogic
Copy link
Member

QuLogic commented Dec 3, 2015

Fixed by #5206, I think.

@QuLogic QuLogic closed this as completed Dec 3, 2015
@QuLogic QuLogic modified the milestones: v1.5.1, 2.0.1 (next bug fix release) Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: consistency Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Projects
None yet
Development

No branches or pull requests

5 participants