@@ -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