8000 pcolorfast simplifications. by anntzer · Pull Request #13327 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

pcolorfast simplifications. #13327

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

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 17 additions & 42 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6254,7 +6254,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
"'norm' must be an instance of 'mcolors.Normalize'")

C = args[-1]
nr, nc = C.shape
nr, nc = np.shape(C)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(supports C being a nested list instead of an array)

if len(args) == 1:
style = "image"
x = [0, nc]
Expand Down Expand Up @@ -6282,54 +6282,29 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
raise TypeError("need 1 argument or 3 arguments")

if style == "quadmesh":

# convert to one dimensional arrays
# This should also be moved to the QuadMesh class

# data point in each cell is value at lower left corner
C = ma.ravel(C)
X = x.ravel()
Y = y.ravel()
Nx = nc + 1
Ny = nr + 1

# The following needs to be cleaned up; the renderer
# requires separate contiguous arrays for X and Y,
# but the QuadMesh class requires the 2D array.
coords = np.empty(((Nx * Ny), 2), np.float64)
coords[:, 0] = X
coords[:, 1] = Y

# The QuadMesh class can also be changed to
# handle relevant superclass kwargs; the initializer
# should do much more than it does now.
collection = mcoll.QuadMesh(nc, nr, coords, 0, edgecolors="None")
collection.set_alpha(alpha)
collection.set_array(C)
collection.set_cmap(cmap)
collection.set_norm(norm)
coords = np.stack([x, y], axis=-1)
collection = mcoll.QuadMesh(
nc, nr, coords,
array=np.ma.ravel(C), alpha=alpha, cmap=cmap, norm=norm,
antialiased=False, edgecolors="none")
self.add_collection(collection, autolim=False)
xl, xr, yb, yt = X.min(), X.max(), Y.min(), Y.max()
xl, xr, yb, yt = x.min(), x.max(), y.min(), y.max()
ret = collection

else: # It's one of the two image styles.
xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]

extent = xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
if style == "image":
im = mimage.AxesImage(self, cmap, norm,
interpolation='nearest',
origin='lower',
extent=(xl, xr, yb, yt),
**kwargs)
im.set_data(C)
im.set_alpha(alpha)
im = mimage.AxesImage(
self, cmap, norm,
data=C, alpha=alpha, extent=extent,
interpolation='nearest', origin='lower',
**kwargs)
elif style == "pcolorimage":
im = mimage.PcolorImage(self, x, y, C,
cmap=cmap,
norm=norm,
alpha=alpha,
**kwargs)
im.set_extent((xl, xr, yb, yt))
im = mimage.PcolorImage(
self, x, y, C,
cmap=cmap, norm=norm, alpha=alpha, extent=extent,
**kwargs)
self.add_image(im)
ret = im

Expand Down
0