@@ -2022,8 +2022,6 @@ def __init__(self, *args, **kwargs):
2022
2022
super ().__init__ (** kwargs )
2023
2023
_api .check_shape ((None , None , 2 ), coordinates = coords )
2024
2024
self ._coordinates = coords
2025
- self ._meshWidth = self ._coordinates .shape [1 ] - 1
2026
- self ._meshHeight = self ._coordinates .shape [0 ] - 1
2027
2025
self ._antialiased = antialiased
2028
2026
self ._shading = shading
2029
2027
@@ -2041,15 +2039,19 @@ def get_paths(self):
2041
2039
return self ._paths
2042
2040
2043
2041
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 )
2046
2043
self .stale = True
2047
2044
2048
2045
def get_datalim (self , transData ):
2049
2046
return (self .get_transform () - transData ).transform_bbox (self ._bbox )
2050
2047
2051
2048
@staticmethod
2049
+ @_api .deprecated ("3.5" , alternative = "QuadMesh(coordinates).get_paths()" )
2052
2050
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 ):
2053
2055
"""
2054
2056
Convert a given mesh into a sequence of `~.Path` objects.
2055
2057
@@ -2060,20 +2062,23 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
2060
2062
c = coordinates .data
2061
2063
else :
2062
2064
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 ))
2071
2072
return [mpath .Path (x ) for x in points ]
2072
2073
2074
+ @_api .deprecated ("3.5" )
2073
2075
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 ):
2074
2079
"""
2075
2080
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
2077
2082
`~.RendererBase.draw_gouraud_triangle`.
2078
2083
"""
2079
2084
if isinstance (coordinates , np .ma .MaskedArray ):
@@ -2086,29 +2091,25 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
2086
2091
p_c = p [1 :, 1 :]
2087
2092
p_d = p [1 :, :- 1 ]
2088
2093
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 ))
2099
2102
c_a = c [:- 1 , :- 1 ]
2100
2103
c_b = c [:- 1 , 1 :]
2101
2104
c_c = c [1 :, 1 :]
2102
2105
c_d = c [1 :, :- 1 ]
2103
2106
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 ))
2112
2113
2113
2114
return triangles , colors
2114
2115
@@ -2147,13 +2148,13 @@ def draw(self, renderer):
2147
2148
gc .set_linewidth (self .get_linewidth ()[0 ])
2148
2149
2149
2150
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 )
2152
2152
renderer .draw_gouraud_triangles (
2153
2153
gc , triangles , colors , transform .frozen ())
2154
2154
else :
2155
2155
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 ,
2157
2158
coordinates , offsets , transOffset ,
2158
2159
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
2159
2160
self .get_facecolor ().reshape ((- 1 , 4 )),
0 commit comments