(axis: Axes, data: Field, dims: tuple, vector: Shape, color: Tensor, alpha: Tensor, err: Tensor, min_val, max_val, label)
| 610 | |
| 611 | @staticmethod |
| 612 | def _plot_points(axis: Axes, data: Field, dims: tuple, vector: Shape, color: Tensor, alpha: Tensor, err: Tensor, min_val, max_val, label): |
| 613 | connected = spatial(data.points) |
| 614 | if isinstance(data.sampled_elements, GeometryStack): |
| 615 | for idx in data.sampled_elements.object_dims.meshgrid(): |
| 616 | PointCloud2D._plot_points(axis, data[idx], dims, vector, color[idx], alpha[idx], err[idx], min_val, max_val, label) |
| 617 | return |
| 618 | elif isinstance(data.sampled_elements, Intersection): |
| 619 | math.assert_close(data.values, math.NAN, msg="Intersections can only be plotted as Geometries, not Fields.") |
| 620 | sdf = CenteredGrid(data.sampled_elements.approximate_signed_distance, bounds=data.sampled_elements.bounding_box().scaled(1.).corner_representation(), **{d: 32 for d in dims}) |
| 621 | sdf_grid = SDFGrid(sdf.values, sdf.bounds, approximate_outside=False) |
| 622 | data = Field(sdf_grid, math.NAN, 0) |
| 623 | data = only_stored_elements(data) |
| 624 | x, y = reshaped_numpy(data.points.vector[dims], ['vector', non_channel(data)]) |
| 625 | if wrap(color == 'cmap').all: |
| 626 | values = reshaped_numpy(data.values, [non_channel(data)]) |
| 627 | mpl_colors = add_color_bar(axis, values, min_val, max_val) |
| 628 | single_color = False |
| 629 | elif non_channel(data).only(color.shape) and color.dtype.kind == float: # use color map |
| 630 | values = reshaped_numpy(color, [non_channel(data)]) |
| 631 | mpl_colors = add_color_bar(axis, values, None, None) |
| 632 | single_color = False |
| 633 | else: |
| 634 | mpl_colors = matplotlib_colors(color, non_channel(data), default=0) |
| 635 | single_color = True |
| 636 | alphas = reshaped_numpy(alpha, [non_channel(data)]) |
| 637 | if isinstance(data.geometry, Point): |
| 638 | if spatial(data.points).is_empty: |
| 639 | axis.scatter(x, y, color=mpl_colors, s=6 ** 2, alpha=alphas) |
| 640 | if (err != 0).any: |
| 641 | x_err = reshaped_numpy(err.vector[dims[0]], [instance(data)]) if dims[0] in err.vector.item_names else 0 |
| 642 | y_err = reshaped_numpy(err.vector[dims[1]], [instance(data)]) if dims[1] in err.vector.item_names else 0 |
| 643 | if all(np.all(c == mpl_colors[0]) for c in mpl_colors) and all(a == alphas[0] for a in alphas): |
| 644 | axis.errorbar(x, y, y_err, x_err, fmt=' ', color=mpl_colors[0], alpha=alphas[0]) |
| 645 | else: |
| 646 | for x_, y_, y_err_, x_err_, col_, alpha_ in zip(x, y, y_err, x_err, mpl_colors, alphas): |
| 647 | axis.errorbar(x_, y_, y_err_, x_err_, fmt=' ', color=col_, alpha=alpha_) |
| 648 | else: |
| 649 | if isinstance(data.geometry, Sphere): |
| 650 | rad = reshaped_numpy(data.geometry.bounding_radius(), [data.shape.non_channel]) |
| 651 | shapes = [plt.Circle((xi, yi), radius=ri, linewidth=0, alpha=a, facecolor=ci) for xi, yi, ri, ci, a in zip(x, y, rad, mpl_colors, alphas)] |
| 652 | axis.add_collection(matplotlib.collections.PatchCollection(shapes, match_original=True)) |
| 653 | elif isinstance(data.geometry, BaseBox): |
| 654 | half_size = data.geometry.half_size |
| 655 | min_len = axis.get_ylim()[1] - axis.get_ylim()[0] + axis.get_xlim()[1] - axis.get_xlim()[0] |
| 656 | half_size = math.where(math.is_finite(half_size), half_size, min_len) |
| 657 | w2, h2 = reshaped_numpy(half_size, ['vector', data.shape.non_channel]) |
| 658 | if data.geometry.rotation_matrix is None: |
| 659 | angles = w2 * 0. |
| 660 | lower_x = x - w2 |
| 661 | lower_y = y - h2 |
| 662 | else: |
| 663 | angles = reshaped_numpy(rotation_angles(data.geometry.rotation_matrix), [data.shape.non_channel]) |
| 664 | lower_x, lower_y = reshaped_numpy(data.geometry.center - rotate(data.geometry.half_size, data.geometry.rotation_matrix), ['vector', data.shape.non_channel]) |
| 665 | shapes = [plt.Rectangle((lxi, lyi), w2i * 2, h2i * 2, angle=ang*180/np.pi, linewidth=1, edgecolor='white', alpha=a, facecolor=ci) for lxi, lyi, w2i, h2i, ang, ci, a in zip(lower_x, lower_y, w2, h2, angles, mpl_colors, alphas)] |
| 666 | axis.add_collection(matplotlib.collections.PatchCollection(shapes, match_original=True)) |
| 667 | elif isinstance(data.geometry, Mesh): |
| 668 | edgecolor = 'white' if single_color else None |
| 669 | csr = data.mesh.elements.numpy().tocsr() |
no test coverage detected