(axis, points: math.Tensor, color: Tensor, alpha: Tensor, dims: Tuple[str], label_axis=True, max_axis_labels=10)
| 761 | |
| 762 | @staticmethod |
| 763 | def _annotate_points(axis, points: math.Tensor, color: Tensor, alpha: Tensor, dims: Tuple[str], label_axis=True, max_axis_labels=10): |
| 764 | labeled_dims = non_channel(points) |
| 765 | labeled_dims = math.concat_shapes(*[d for d in labeled_dims if d.item_names[0]]) |
| 766 | if not labeled_dims: |
| 767 | return |
| 768 | if all(dim.name in points.shape.get_item_names('vector') for dim in labeled_dims): |
| 769 | if label_axis: |
| 770 | for labeled_dim in labeled_dims: |
| 771 | if len(labeled_dim.item_names[0]) <= max_axis_labels: |
| 772 | if points.vector[labeled_dim.name].shape.without(labeled_dims).volume > 1: |
| 773 | return # we'd have to duplicate names |
| 774 | which_axis = dims.index(labeled_dim.name) |
| 775 | set_ticks(axis, which_axis, reshaped_numpy(points.vector[labeled_dim.name], [shape])) |
| 776 | return # The point labels match one of the figure axes, so they are redundant |
| 777 | if points.shape['vector'].size == 2: |
| 778 | np_points = points.numpy([..., 'vector']) |
| 779 | rel_pos = axis.transAxes.inverted().transform(axis.transData.transform(np_points)) |
| 780 | x_view = axis.get_xlim()[1] - axis.get_xlim()[0] |
| 781 | y_view = axis.get_ylim()[1] - axis.get_ylim()[0] |
| 782 | for (x, y), (rx, ry), idx, idx_n in zip(np_points, rel_pos, labeled_dims.meshgrid(), labeled_dims.meshgrid(names=True)): |
| 783 | horizontal_align = 'right' if rx >= .5 else 'left' |
| 784 | if axis.get_xscale() == 'log': |
| 785 | offset_x = x * (1 + .0003 * x_view) if rx < .5 else x * (1 - .0003 * x_view) |
| 786 | else: |
| 787 | offset_x = x + .01 * x_view if rx < .5 else x - .01 * x_view |
| 788 | if axis.get_yscale() == 'log': |
| 789 | offset_y = y * (1 + .0003 * y_view) if ry < .5 else y * (1 - .0003 * y_view) |
| 790 | else: |
| 791 | offset_y = y + .01 * y_view if ry < .5 else y - .01 * y_view |
| 792 | axis.text(offset_x, offset_y, index_label(idx_n), color=_plt_col(color[idx]), alpha=float(alpha[idx]), ha=horizontal_align) |
| 793 | |
| 794 | |
| 795 | class PointCloud3D(Recipe): |
no test coverage detected