Source code for data_morph.shapes.lines

"""Shapes that are lines of lines."""

import numpy as np

from ..data.dataset import Dataset
from .bases.line_collection import LineCollection


[docs] class HighLines(LineCollection): """ Class for the high lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import HighLines _ = HighLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.data_bounds.x_bounds y_bounds = dataset.data_bounds.y_bounds offset = y_bounds.range / 5 lower = y_bounds[0] + offset upper = y_bounds[1] - offset super().__init__( [[x_bounds[0], lower], [x_bounds[1], lower]], [[x_bounds[0], upper], [x_bounds[1], upper]], ) def __str__(self) -> str: return 'high_lines'
[docs] class HorizontalLines(LineCollection): """ Class for the horizontal lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import HorizontalLines _ = HorizontalLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.data_bounds.x_bounds y_bounds = dataset.data_bounds.y_bounds super().__init__( *[ [[x_bounds[0], y], [x_bounds[1], y]] for y in np.linspace(y_bounds[0], y_bounds[1], 5) ] ) def __str__(self) -> str: return 'h_lines'
[docs] class SlantDownLines(LineCollection): """ Class for the slant down lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import SlantDownLines _ = SlantDownLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.morph_bounds.x_bounds y_bounds = dataset.morph_bounds.y_bounds xmin, xmax = x_bounds xmid = xmin + x_bounds.range / 2 x_offset = (xmid - xmin) / 2 ymin, ymax = y_bounds ymid = ymin + y_bounds.range / 2 y_offset = (ymid - ymin) / 2 super().__init__( [[xmin, ymid], [xmid, ymin]], [[xmin, ymid + y_offset], [xmid + x_offset, ymin]], [[xmin, ymax], [xmax, ymin]], [[xmin + x_offset, ymax], [xmax, ymin + y_offset]], [[xmid, ymax], [xmax, ymid]], ) def __str__(self) -> str: return 'slant_down'
[docs] class SlantUpLines(LineCollection): """ Class for the slant up lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import SlantUpLines _ = SlantUpLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.morph_bounds.x_bounds y_bounds = dataset.morph_bounds.y_bounds xmin, xmax = x_bounds xmid = xmin + x_bounds.range / 2 x_offset = (xmid - xmin) / 2 ymin, ymax = y_bounds ymid = ymin + y_bounds.range / 2 y_offset = (ymid - ymin) / 2 super().__init__( [[xmin, ymid], [xmid, ymax]], [[xmin, ymin + y_offset], [xmid + x_offset, ymax]], [[xmin, ymin], [xmax, ymax]], [[xmin + x_offset, ymin], [xmax, ymid + y_offset]], [[xmid, ymin], [xmax, ymid]], ) def __str__(self) -> str: return 'slant_up'
[docs] class VerticalLines(LineCollection): """ Class for the vertical lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import VerticalLines _ = VerticalLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.data_bounds.x_bounds y_bounds = dataset.data_bounds.y_bounds super().__init__( *[ [[x, y_bounds[0]], [x, y_bounds[1]]] for x in np.linspace(x_bounds[0], x_bounds[1], 5) ] ) def __str__(self) -> str: return 'v_lines'
[docs] class WideLines(LineCollection): """ Class for the wide lines shape. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import WideLines _ = WideLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: x_bounds = dataset.data_bounds.x_bounds y_bounds = dataset.data_bounds.y_bounds offset = x_bounds.range / 5 lower = x_bounds[0] + offset upper = x_bounds[1] - offset super().__init__( [[lower, y_bounds[0]], [lower, y_bounds[1]]], [[upper, y_bounds[0]], [upper, y_bounds[1]]], ) def __str__(self) -> str: return 'wide_lines'
[docs] class XLines(LineCollection): """ Class for the X shape consisting of two crossing, perpendicular lines. .. plot:: :scale: 75 :caption: This shape is generated using the panda dataset. from data_morph.data.loader import DataLoader from data_morph.shapes.lines import XLines _ = XLines(DataLoader.load_dataset('panda')).plot() Parameters ---------- dataset : Dataset The starting dataset to morph into other shapes. """ def __init__(self, dataset: Dataset) -> None: xmin, xmax = dataset.morph_bounds.x_bounds ymin, ymax = dataset.morph_bounds.y_bounds super().__init__([[xmin, ymin], [xmax, ymax]], [[xmin, ymax], [xmax, ymin]]) def __str__(self) -> str: return 'x'