Class for the efficient drawing of a triangular mesh using Gouraud shading. A triangular mesh is a `~matplotlib.tri.Triangulation` object.
| 2264 | |
| 2265 | |
| 2266 | class TriMesh(Collection): |
| 2267 | """ |
| 2268 | Class for the efficient drawing of a triangular mesh using Gouraud shading. |
| 2269 | |
| 2270 | A triangular mesh is a `~matplotlib.tri.Triangulation` object. |
| 2271 | """ |
| 2272 | def __init__(self, triangulation, **kwargs): |
| 2273 | super().__init__(**kwargs) |
| 2274 | self._triangulation = triangulation |
| 2275 | self._shading = 'gouraud' |
| 2276 | |
| 2277 | self._bbox = transforms.Bbox.unit() |
| 2278 | |
| 2279 | # Unfortunately this requires a copy, unless Triangulation |
| 2280 | # was rewritten. |
| 2281 | xy = np.hstack((triangulation.x.reshape(-1, 1), |
| 2282 | triangulation.y.reshape(-1, 1))) |
| 2283 | self._bbox.update_from_data_xy(xy) |
| 2284 | |
| 2285 | def get_paths(self): |
| 2286 | if self._paths is None: |
| 2287 | self.set_paths() |
| 2288 | return self._paths |
| 2289 | |
| 2290 | def set_paths(self): |
| 2291 | self._paths = self.convert_mesh_to_paths(self._triangulation) |
| 2292 | |
| 2293 | @staticmethod |
| 2294 | def convert_mesh_to_paths(tri): |
| 2295 | """ |
| 2296 | Convert a given mesh into a sequence of `.Path` objects. |
| 2297 | |
| 2298 | This function is primarily of use to implementers of backends that do |
| 2299 | not directly support meshes. |
| 2300 | """ |
| 2301 | triangles = tri.get_masked_triangles() |
| 2302 | verts = np.stack((tri.x[triangles], tri.y[triangles]), axis=-1) |
| 2303 | return [mpath.Path(x) for x in verts] |
| 2304 | |
| 2305 | @artist.allow_rasterization |
| 2306 | def draw(self, renderer): |
| 2307 | if not self.get_visible(): |
| 2308 | return |
| 2309 | renderer.open_group(self.__class__.__name__, gid=self.get_gid()) |
| 2310 | transform = self.get_transform() |
| 2311 | |
| 2312 | # Get a list of triangles and the color at each vertex. |
| 2313 | tri = self._triangulation |
| 2314 | triangles = tri.get_masked_triangles() |
| 2315 | |
| 2316 | verts = np.stack((tri.x[triangles], tri.y[triangles]), axis=-1) |
| 2317 | |
| 2318 | self.update_scalarmappable() |
| 2319 | colors = self._facecolors[triangles] |
| 2320 | |
| 2321 | gc = renderer.new_gc() |
| 2322 | self._set_gc_clip(gc) |
| 2323 | gc.set_linewidth(self.get_linewidth()[0]) |
no outgoing calls
no test coverage detected
searching dependent graphs…