|
| 1 | +"""Diagnostic plot to visualize a shape superimposed on the dataset.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING |
| 6 | + |
| 7 | +from ..plotting.style import plot_with_custom_style |
| 8 | + |
| 9 | +if TYPE_CHECKING: |
| 10 | + from numbers import Number |
| 11 | + |
| 12 | + from matplotlib.axes import Axes |
| 13 | + |
| 14 | + from ..data.dataset import Dataset |
| 15 | + from ..shapes.bases.shape import Shape |
| 16 | + |
| 17 | + |
| 18 | +@plot_with_custom_style |
| 19 | +def plot_shape_on_dataset( |
| 20 | + dataset: Dataset, |
| 21 | + shape: Shape, |
| 22 | + show_bounds: bool = False, |
| 23 | + alpha: Number = 0.25, |
| 24 | +) -> Axes: |
| 25 | + """ |
| 26 | + Plot a shape superimposed on a dataset to evaluate heuristics. |
| 27 | +
|
| 28 | + Parameters |
| 29 | + ---------- |
| 30 | + dataset : Dataset |
| 31 | + The dataset that ``shape`` was instantiated with. |
| 32 | + shape : Shape |
| 33 | + The shape that was instantiated with ``dataset``. |
| 34 | + show_bounds : bool, default ``False`` |
| 35 | + Whether to include the dataset's bounds in the plot. |
| 36 | + alpha : Number, default ``0.25`` |
| 37 | + The transparency to use for the dataset's points. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + matplotlib.axes.Axes |
| 42 | + The :class:`~matplotlib.axes.Axes` object containing the plot. |
| 43 | +
|
| 44 | + Examples |
| 45 | + -------- |
| 46 | +
|
| 47 | + .. plot:: |
| 48 | + :scale: 75 |
| 49 | + :include-source: |
| 50 | + :caption: |
| 51 | + Visualization of the :class:`.Star` shape when calculated based on the |
| 52 | + music :class:`.Dataset`, with the dataset's bounds. |
| 53 | +
|
| 54 | + from data_morph.data.loader import DataLoader |
| 55 | + from data_morph.plotting.diagnostics import plot_shape_on_dataset |
| 56 | + from data_morph.shapes.lines import Star |
| 57 | +
|
| 58 | + dataset = DataLoader.load_dataset('music') |
| 59 | + shape = Star(dataset) |
| 60 | + plot_shape_on_dataset(dataset, shape, show_bounds=True, alpha=0.1) |
| 61 | +
|
| 62 | + .. plot:: |
| 63 | + :scale: 75 |
| 64 | + :include-source: |
| 65 | + :caption: |
| 66 | + Visualization of the :class:`.Heart` shape when calculated based on the |
| 67 | + music :class:`.Dataset`, without the dataset's bounds. |
| 68 | +
|
| 69 | + from data_morph.data.loader import DataLoader |
| 70 | + from data_morph.plotting.diagnostics import plot_shape_on_dataset |
| 71 | + from data_morph.shapes.points import Heart |
| 72 | +
|
| 73 | + dataset = DataLoader.load_dataset('music') |
| 74 | + shape = Heart(dataset) |
| 75 | + plot_shape_on_dataset(dataset, shape, alpha=0.1) |
| 76 | + """ |
| 77 | + ax = dataset.plot(show_bounds=show_bounds, title=None, alpha=alpha) |
| 78 | + shape.plot(ax=ax) |
| 79 | + return ax |
0 commit comments