FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Pad Axes3D.plot_surface inputs to allow for vectorized processing by apaszke · Pull Request #16699 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .png  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
65 changes: 26 additions & 39 deletions lib/mpl_toolkits/mplot3d/axes3d.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1437,17 +1437,6 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
the input data is larger, it will be downsampled (by slicing) to
these numbers of points.

.. note::

To maximize rendering speed consider setting *rstride* and *cstride*
to divisors of the number of rows minus 1 and columns minus 1
respectively. For example, given 51 rows rstride can be any of the
divisors of 50.

Similarly, a setting of *rstride* and *cstride* equal to 1 (or
*rcount* and *ccount* equal the number of rows and columns) can use
the optimized path.

Parameters
----------
X, Y, Z : 2d arrays
Expand Down Expand Up @@ -1533,7 +1522,7 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
cstride = int(max(np.ceil(cols / ccount), 1))

if 'facecolors' in kwargs:
fcolors = kwargs.pop('facecolors')
fcolors = np.asarray(kwargs.pop('facecolors'))
else:
color = kwargs.pop('color', None)
if color is None:
Expand All @@ -1551,33 +1540,31 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
"semantic or raise an error in matplotlib 3.3. "
"Please use shade=False instead.")

colset = [] # the sampled facecolor
if (rows - 1) % rstride == 0 and \
(cols - 1) % cstride == 0 and \
fcolors is None:
polys = np.stack(
[cbook._array_patch_perimeters(a, rstride, cstride)
for a in (X, Y, Z)],
axis=-1)
else:
# evenly spaced, and including both endpoints
row_inds = list(range(0, rows-1, rstride)) + [rows-1]
col_inds = list(range(0, cols-1, cstride)) + [cols-1]

polys = []
for rs, rs_next in zip(row_inds[:-1], row_inds[1:]):
for cs, cs_next in zip(col_inds[:-1], col_inds[1:]):
ps = [
# +1 ensures we share edges between polygons
cbook._array_perimeter(a[rs:rs_next+1, cs:cs_next+1])
for a in (X, Y, Z)
]
# ps = np.stack(ps, axis=-1)
ps = np.array(ps).T
polys.append(ps)

if fcolors is not None:
colset.append(fcolors[rs][cs])
# Calculate the minimal amount of padding that will allow us to extract
# vectorized patches.
rrem = (rows - 1) % rstride
rpadding = rstride - rrem if rrem != 0 else 0
crem = (cols - 1) % cstride
cpadding = cstride - crem if crem != 0 else 0

def pad_for_patches(a):
if cpadding == 0 and rpadding == 0:
return a
result = np.empty_like(a, shape=(rows + rpadding, cols + cpadding))
result[:rows, :cols] = a
result[:rows, cols:] = a[:, -1:]
result[rows:, :cols] = a[-1:, :]
result[rows:, cols:] = a[-1, -1]
return result

polys = np.stack(
[cbook._array_patch_perimeters(pad_for_patches(a),
rstride, cstride)
for a in (X, Y, Z)],
axis=-1)
if fcolors is not None:
colset = fcolors[np.ix_(np.arange(0, rows-1, rstride),
np.arange(0, cols-1, cstride))]

# note that the striding causes some polygons to have more coordinates
# than others
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.

Back | FazBrowse Home | New Git URL