(self, data: Field, figure, subplot, space: Box, min_val: float, max_val: float, show_color_bar: bool, color: Tensor, alpha: Tensor, err: Tensor)
| 798 | return data.is_point_cloud and data.spatial_rank == 3 |
| 799 | |
| 800 | def plot(self, data: Field, figure, subplot, space: Box, min_val: float, max_val: float, show_color_bar: bool, color: Tensor, alpha: Tensor, err: Tensor): |
| 801 | dims = space.vector.item_names |
| 802 | vector = data.geometry.shape['vector'] |
| 803 | channels = channel(data.points).without('vector') |
| 804 | for idx in channels.meshgrid(names=True): |
| 805 | x, y, z = reshaped_numpy(data[idx].points.vector[dims], [vector, non_channel(data)]) |
| 806 | mpl_colors = matplotlib_colors(color[idx], non_channel(data), default=0) |
| 807 | alphas = reshaped_numpy(alpha[idx], [non_channel(data)]) |
| 808 | M = subplot.transData.get_matrix() |
| 809 | x_scale, y_scale, z_scale = M[0, 0], M[1, 1], M[2, 2] |
| 810 | if isinstance(data.geometry, Sphere): |
| 811 | rx, ry, rz = reshaped_numpy(data.geometry.radius, [vector, data.geometry.shape.without('vector')]) |
| 812 | u, v = np.linspace(0, 2 * np.pi, 100), np.linspace(0, np.pi, 100) # Set of all spherical angles |
| 813 | # --- Cartesian coordinates that correspond to the spherical angles --- |
| 814 | for i in range(len(x)): |
| 815 | x_ = x[i] + rx[i] * np.outer(np.cos(u), np.sin(v)) |
| 816 | y_ = y[i] + ry[i] * np.outer(np.sin(u), np.sin(v)) |
| 817 | z_ = z[i] + rz[i] * np.outer(np.ones_like(u), np.cos(v)) |
| 818 | plot_surface(subplot, x_, y_, z_, rstride=4, cstride=4, color=mpl_colors[0], alpha=alphas[0]) |
| 819 | elif isinstance(data.geometry, BaseBox): |
| 820 | a = alphas[0] |
| 821 | c = mpl_colors[0] |
| 822 | # ToDo support collections of boxes |
| 823 | cx, cy, cz = math.reshaped_numpy(data.geometry.corners, ['vector', *['~'+d for d in dims]]) |
| 824 | plot_surface(subplot, cx[:, :, 1], cy[:, :, 1], cz[:, :, 1], alpha=a, color=c) |
| 825 | plot_surface(subplot, cx[:, :, 0], cy[:, :, 0], cz[:, :, 0], alpha=a, color=c) |
| 826 | plot_surface(subplot, cx[:, 1, :], cy[:, 1, :], cz[:, 1, :], alpha=a, color=c) |
| 827 | plot_surface(subplot, cx[:, 0, :], cy[:, 0, :], cz[:, 0, :], alpha=a, color=c) |
| 828 | plot_surface(subplot, cx[1, :, :], cy[1, :, :], cz[1, :, :], alpha=a, color=c) |
| 829 | plot_surface(subplot, cx[0, :, :], cy[0, :, :], cz[0, :, :], alpha=a, color=c) |
| 830 | elif isinstance(data.geometry, Point): |
| 831 | if not spatial(data.geometry): |
| 832 | size = 6 / (0.5 * (x_scale+y_scale+z_scale)/3) |
| 833 | subplot.scatter(x, y, z, color=mpl_colors, alpha=alphas, s=(size * 0.5 * (x_scale + y_scale + z_scale) / 3) ** 2) |
| 834 | elif isinstance(data.geometry, _EmbeddedGeometry): |
| 835 | raise NotImplementedError(f"Plotting embedded geometries not yet supported") |
| 836 | else: |
| 837 | size = data.geometry.bounding_radius().numpy() |
| 838 | subplot.scatter(x, y, z, marker='X', color=mpl_colors, alpha=alphas, s=(size * 0.5 * (x_scale + y_scale + z_scale) / 3) ** 2) |
| 839 | if spatial(data.geometry): # Connect by lines |
| 840 | for i, idx in enumerate(instance(data).meshgrid()): |
| 841 | for sp_dim in spatial(data.geometry): |
| 842 | other_sp = spatial(data.geometry).without(sp_dim) |
| 843 | xs, ys, zs = reshaped_numpy(data[idx].points.vector[dims], [vector, sp_dim, other_sp]) |
| 844 | if (color == None).all: |
| 845 | col = _next_line_color(subplot) |
| 846 | else: |
| 847 | col = _plt_col(color) |
| 848 | alpha_f = float(alpha[idx].max) |
| 849 | if ((err[idx] != 0) & (err[idx] != None)).any: |
| 850 | x_errs = reshaped_numpy(err[idx].vector[dims[0]], [other_sp, sp_dim]) if dims[0] in err.vector.item_names else 0 |
| 851 | y_errs = reshaped_numpy(err[idx].vector[dims[1]], [other_sp, sp_dim]) if dims[1] in err.vector.item_names else 0 |
| 852 | for x, y, x_err, y_err in zip(xs.T, ys.T, x_errs, y_errs): |
| 853 | if math.max(x_err) > math.max(y_err): |
| 854 | subplot.fill_betweenx(y, x - x_err, x + x_err, color=col, alpha=alpha_f * .2) |
| 855 | else: |
| 856 | subplot.fill_between(x, y - y_err, y + y_err, color=col, alpha=alpha_f * .2) |
| 857 | for i in range(xs.shape[1]): |
nothing calls this directly
no test coverage detected