8000 pcolorfast simplifications. · matplotlib/matplotlib@9940d44 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9940d44

Browse files
committed
pcolorfast simplifications.
1 parent e714048 commit 9940d44

File tree

1 file changed

+17
-42
lines changed

1 file changed

+17
-42
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,7 +6213,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62136213
"'norm' must be an instance of 'mcolors.Normalize'")
62146214

62156215
C = args[-1]
6216-
nr, nc = C.shape
6216+
nr, nc = np.shape(C)
62176217
if len(args) == 1:
62186218
style = "image"
62196219
x = [0, nc]
@@ -6241,54 +6241,29 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62416241
raise TypeError("need 1 argument or 3 arguments")
62426242

62436243
if style == "quadmesh":
6244-
6245-
# convert to one dimensional arrays
6246-
# This should also be moved to the QuadMesh class
6247-
62486244
# data point in each cell is value at lower left corner
6249-
C = ma.ravel(C)
6250-
X = x.ravel()
6251-
Y = y.ravel()
6252-
Nx = nc + 1
6253-
Ny = nr + 1
6254-
6255-
# The following needs to be cleaned up; the renderer
6256-
# requires separate contiguous arrays for X and Y,
6257-
# but the QuadMesh class requires the 2D array.
6258-
coords = np.empty(((Nx * Ny), 2), np.float64)
6259-
coords[:, 0] = X
6260-
coords[:, 1] = Y
6261-
6262-
# The QuadMesh class can also be changed to
6263-
# handle relevant superclass kwargs; the initializer
6264-
# should do much more than it does now.
6265-
collection = mcoll.QuadMesh(nc, nr, coords, 0, edgecolors="None")
6266-
collection.set_alpha(alpha)
6267-
collection.set_array(C)
6268-
collection.set_cmap(cmap)
6269-
collection.set_norm(norm)
6245+
coords = np.stack([x, y], axis=-1)
6246+
collection = mcoll.QuadMesh(
6247+
nc, nr, coords,
6248+
array=ma.ravel(C), alpha=alpha, cmap=cmap, norm=norm,
6249+
antialiased=False, edgecolors="none")
62706250
self.add_collection(collection, autolim=False)
6271-
xl, xr, yb, yt = X.min(), X.max(), Y.min(), Y.max()
6251+
xl, xr, yb, yt = x.min(), x.max(), y.min(), y.max()
62726252
ret = collection
62736253

62746254
else: # It's one of the two image styles.
6275-
xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
6276-
6255+
extent = xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
62776256
if style == "image":
6278-
im = mimage.AxesImage(self, cmap, norm,
6279-
interpolation='nearest',
6280-
origin='lower',
6281-
extent=(xl, xr, yb, yt),
6282-
**kwargs)
6283-
im.set_data(C)
6284-
im.set_alpha(alpha)
6257+
im = mimage.AxesImage(
6258+
self, cmap, norm,
6259+
data=C, alpha=alpha, extent=extent,
6260+
interpolation='nearest', origin='lower',
6261+
**kwargs)
62856262
elif style == "pcolorimage":
6286-
im = mimage.PcolorImage(self, x, y, C,
6287-
cmap=cmap,
6288-
norm=norm,
6289-
alpha=alpha,
6290-
**kwargs)
6291-
im.set_extent((xl, xr, yb, yt))
6263+
im = mimage.PcolorImage(
6264+
self, x, y, C,
6265+
cmap=cmap, norm=norm, alpha=alpha, extent=extent,
6266+
**kwargs)
62926267
self.add_image(im)
62936268
ret = im
62946269

0 commit comments

Comments
 (0)
0