Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dcd83b3

Browse filesBrowse files
committed
Further remove use of meshWidth, meshHeight in QuadMesh.
convert_mesh_to_paths and convert_mesh_to_triangles both rely on non-flat indexing of `coordinates`, and don't actually need the meshWidth and meshHeight arguments (they are only used in calls to reshape(), but reshape() can just use -1 for the unknown dimension). Instead of going through signature deprecation, just deprecate the methods, which are essentially helpers to generate calls to draw_quad_mesh and draw_gouraud_triangles.
1 parent c56e3c5 commit dcd83b3
Copy full SHA for dcd83b3

File tree

Expand file treeCollapse file tree

3 files changed

+40
-36
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+40
-36
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``QuadMesh.convert_mesh_to_paths`` and ``QuadMesh.convert_mesh_to_triangles``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated. ``QuadMesh.get_paths()`` can be used as an alternative for
4+
the former; there is no replacement for the latter.

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
270270
"""
271271

272272
from matplotlib.collections import QuadMesh
273-
paths = QuadMesh.convert_mesh_to_paths(
274-
meshWidth, meshHeight, coordinates)
273+
paths = QuadMesh._convert_mesh_to_paths(coordinates)
275274

276275
if edgecolors is None:
277276
edgecolors = facecolors

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+35-34Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,6 @@ def __init__(self, *args, **kwargs):
20222022
super().__init__(**kwargs)
20232023
_api.check_shape((None, None, 2), coordinates=coords)
20242024
self._coordinates = coords
2025-
self._meshWidth = self._coordinates.shape[1] - 1
2026-
self._meshHeight = self._coordinates.shape[0] - 1
20272025
self._antialiased = antialiased
20282026
self._shading = shading
20292027

@@ -2041,15 +2039,19 @@ def get_paths(self):
20412039
return self._paths
20422040

20432041
def set_paths(self):
2044-
self._paths = self.convert_mesh_to_paths(
2045-
self._meshWidth, self._meshHeight, self._coordinates)
2042+
self._paths = self._convert_mesh_to_paths(self._coordinates)
20462043
self.stale = True
20472044

20482045
def get_datalim(self, transData):
20492046
return (self.get_transform() - transData).transform_bbox(self._bbox)
20502047

20512048
@staticmethod
2049+
@_api.deprecated("3.5", alternative="QuadMesh(coordinates).get_paths()")
20522050
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
2051+
return QuadMesh._convert_mesh_to_paths(coordinates)
2052+
2053+
@staticmethod
2054+
def _convert_mesh_to_paths(coordinates):
20532055
"""
20542056
Convert a given mesh into a sequence of `~.Path` objects.
20552057
@@ -2060,20 +2062,23 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
20602062
c = coordinates.data
20612063
else:
20622064
c = coordinates
2063-
points = np.concatenate((
2064-
c[:-1, :-1],
2065-
c[:-1, 1:],
2066-
c[1:, 1:],
2067-
c[1:, :-1],
2068-
c[:-1, :-1]
2069-
), axis=2)
2070-
points = points.reshape((meshWidth * meshHeight, 5, 2))
2065+
points = np.concatenate([
2066+
c[:-1, :-1],
2067+
c[:-1, 1:],
2068+
c[1:, 1:],
2069+
c[1:, :-1],
2070+
c[:-1, :-1]
2071+
], axis=2).reshape((-1, 5, 2))
20712072
return [mpath.Path(x) for x in points]
20722073

2074+
@_api.deprecated("3.5")
20732075
def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
2076+
return self._convert_mesh_to_triangles(coordinates)
2077+
2078+
def _convert_mesh_to_triangles(self, coordinates):
20742079
"""
20752080
Convert a given mesh into a sequence of triangles, each point
2076-
with its own color. This is useful for experiments using
2081+
with its own color. The result can be used to construct a call to
20772082
`~.RendererBase.draw_gouraud_triangle`.
20782083
"""
20792084
if isinstance(coordinates, np.ma.MaskedArray):
@@ -2086,29 +2091,25 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
20862091
p_c = p[1:, 1:]
20872092
p_d = p[1:, :-1]
20882093
p_center = (p_a + p_b + p_c + p_d) / 4.0
2089-
2090-
triangles = np.concatenate((
2091-
p_a, p_b, p_center,
2092-
p_b, p_c, p_center,
2093-
p_c, p_d, p_center,
2094-
p_d, p_a, p_center,
2095-
), axis=2)
2096-
triangles = triangles.reshape((meshWidth * meshHeight * 4, 3, 2))
2097-
2098-
c = self.get_facecolor().reshape((meshHeight + 1, meshWidth + 1, 4))
2094+
triangles = np.concatenate([
2095+
p_a, p_b, p_center,
2096+
p_b, p_c, p_center,
2097+
p_c, p_d, p_center,
2098+
p_d, p_a, p_center,
2099+
], axis=2).reshape((-1, 3, 2))
2100+
2101+
c = self.get_facecolor().reshape((*coordinates.shape[:2], 4))
20992102
c_a = c[:-1, :-1]
21002103
c_b = c[:-1, 1:]
21012104
c_c = c[1:, 1:]
21022105
c_d = c[1:, :-1]
21032106
c_center = (c_a + c_b + c_c + c_d) / 4.0
2104-
2105-
colors = np.concatenate((
2106-
c_a, c_b, c_center,
2107-
c_b, c_c, c_center,
2108-
c_c, c_d, c_center,
2109-
c_d, c_a, c_center,
2110-
), axis=2)
2111-
colors = colors.reshape((meshWidth * meshHeight * 4, 3, 4))
2107+
colors = np.concatenate([
2108+
c_a, c_b, c_center,
2109+
c_b, c_c, c_center,
2110+
c_c, c_d, c_center,
2111+
c_d, c_a, c_center,
2112+
], axis=2).reshape((-1, 3, 4))
21122113

21132114
return triangles, colors
21142115

@@ -2147,13 +2148,13 @@ def draw(self, renderer):
21472148
gc.set_linewidth(self.get_linewidth()[0])
21482149

21492150
if self._shading == 'gouraud':
2150-
triangles, colors = self.convert_mesh_to_triangles(
2151-
self._meshWidth, self._meshHeight, coordinates)
2151+
triangles, colors = self._convert_mesh_to_triangles(coordinates)
21522152
renderer.draw_gouraud_triangles(
21532153
gc, triangles, colors, transform.frozen())
21542154
else:
21552155
renderer.draw_quad_mesh(
2156-
gc, transform.frozen(), self._meshWidth, self._meshHeight,
2156+
gc, transform.frozen(),
2157+
coordinates.shape[1] - 1, coordinates.shape[0] - 1,
21572158
coordinates, offsets, transOffset,
21582159
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
21592160
self.get_facecolor().reshape((-1, 4)),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.