Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions matthewplotlib/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@
![](images/colormaps.png)
"""

from typing import Callable
from typing import Callable, Union
from typing_extensions import TypeAlias
from numpy.typing import ArrayLike

import numpy as np


# # #
# # #
# COLORMAP TYPES


type ContinuousColorMap = Callable[
ContinuousColorMap: TypeAlias = Callable[
[ArrayLike],
np.ndarray,
] # float[...] -> uint8[..., 3]


type DiscreteColorMap = Callable[
DiscreteColorMap: TypeAlias = Callable[
[ArrayLike],
np.ndarray,
] # int[...] -> uint8[..., 3]


type ColorMap = ContinuousColorMap | DiscreteColorMap
ColorMap: TypeAlias = Union[ContinuousColorMap, DiscreteColorMap]


# # #
Expand Down
21 changes: 12 additions & 9 deletions matthewplotlib/colors.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
from __future__ import annotations

from typing import Union
from typing_extensions import TypeAlias

import numpy as np

from numpy.typing import NDArray


# # #
# # #
# COLOR TYPES


type Color = NDArray # uint8[3]
Color: TypeAlias = NDArray # uint8[3]


type ColorLike = (
str
| NDArray # float[3] (0 to 1) or uint8[3] (0 to 255)
| tuple[int, int, int]
| tuple[float, float, float]
| Color
)
ColorLike: TypeAlias = Union[
str,
NDArray, # float[3] (0 to 1) or uint8[3] (0 to 255)
"tuple[int, int, int]",
"tuple[float, float, float]",
Color,
]


# # #
Expand Down
49 changes: 25 additions & 24 deletions matthewplotlib/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import dataclasses
from typing import cast
from typing import Union, cast
from typing_extensions import TypeAlias

import numpy as np
import einops
Expand All @@ -10,38 +11,38 @@
from matthewplotlib.colors import ColorLike, parse_color


# # #
# # #
# Types


type number = int | float | np.integer | np.floating
number: TypeAlias = Union[int, float, "np.integer", "np.floating"]


type ColorSpec = (
None
| ColorLike
| ArrayLike # uint8[n, 3]
)
ColorSpec: TypeAlias = Union[
None,
ColorLike,
ArrayLike, # uint8[n, 3]
]


type Series = (
NDArray # number[n,2]
| tuple[NDArray, ColorSpec] # number[n,2], colors
| tuple[ArrayLike, ArrayLike] # number[n]^2
| tuple[ArrayLike, ArrayLike, ColorSpec] # number[n]^2, colors
| axis # axis
| tuple[axis, ColorSpec] # axis, colors
)
Series: TypeAlias = Union[
NDArray, # number[n,2]
"tuple[NDArray, ColorSpec]", # number[n,2], colors
"tuple[ArrayLike, ArrayLike]", # number[n]^2
"tuple[ArrayLike, ArrayLike, ColorSpec]", # number[n]^2, colors
"axis", # axis
"tuple[axis, ColorSpec]", # axis, colors
]


type Series3 = (
NDArray # number[n,3]
| tuple[NDArray, ColorSpec] # number[n,3], colors
| tuple[ArrayLike, ArrayLike, ArrayLike] # number[n]^3
| tuple[ArrayLike, ArrayLike, ArrayLike, ColorSpec] # number[n]^3, colors
| axis # axis
| tuple[axis, ColorSpec] # axis, uint8[n,rgb]
)
Series3: TypeAlias = Union[
NDArray, # number[n,3]
"tuple[NDArray, ColorSpec]", # number[n,3], colors
"tuple[ArrayLike, ArrayLike, ArrayLike]", # number[n]^3
"tuple[ArrayLike, ArrayLike, ArrayLike, ColorSpec]", # number[n]^3, colors
"axis", # axis
"tuple[axis, ColorSpec]", # axis, uint8[n,rgb]
]


# # #
Expand Down