MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _convert_mesh_to_triangles

Method _convert_mesh_to_triangles

lib/matplotlib/collections.py:2440–2480  ·  view source on GitHub ↗

Convert a given mesh into a sequence of triangles, each point with its own color. The result can be used to construct a call to `~.RendererBase.draw_gouraud_triangles`.

(self, coordinates)

Source from the content-addressed store, hash-verified

2438 return [mpath.Path(x) for x in points]
2439
2440 def _convert_mesh_to_triangles(self, coordinates):
2441 """
2442 Convert a given mesh into a sequence of triangles, each point
2443 with its own color. The result can be used to construct a call to
2444 `~.RendererBase.draw_gouraud_triangles`.
2445 """
2446 if isinstance(coordinates, np.ma.MaskedArray):
2447 p = coordinates.data
2448 else:
2449 p = coordinates
2450
2451 p_a = p[:-1, :-1]
2452 p_b = p[:-1, 1:]
2453 p_c = p[1:, 1:]
2454 p_d = p[1:, :-1]
2455 p_center = (p_a + p_b + p_c + p_d) / 4.0
2456 triangles = np.concatenate([
2457 p_a, p_b, p_center,
2458 p_b, p_c, p_center,
2459 p_c, p_d, p_center,
2460 p_d, p_a, p_center,
2461 ], axis=2).reshape((-1, 3, 2))
2462
2463 c = self.get_facecolor().reshape((*coordinates.shape[:2], 4))
2464 z = self.get_array()
2465 mask = z.mask if np.ma.is_masked(z) else None
2466 if mask is not None:
2467 c[mask, 3] = np.nan
2468 c_a = c[:-1, :-1]
2469 c_b = c[:-1, 1:]
2470 c_c = c[1:, 1:]
2471 c_d = c[1:, :-1]
2472 c_center = (c_a + c_b + c_c + c_d) / 4.0
2473 colors = np.concatenate([
2474 c_a, c_b, c_center,
2475 c_b, c_c, c_center,
2476 c_c, c_d, c_center,
2477 c_d, c_a, c_center,
2478 ], axis=2).reshape((-1, 3, 4))
2479 tmask = np.isnan(colors[..., 2, 3])
2480 return triangles[~tmask], colors[~tmask]
2481
2482
2483class QuadMesh(_MeshData, Collection):

Callers 1

drawMethod · 0.80

Calls 2

get_facecolorMethod · 0.95
get_arrayMethod · 0.80

Tested by

no test coverage detected