|
9 | 9 | gradient = np.vstack((gradient, gradient)) |
10 | 10 |
|
11 | 11 | if TYPE_CHECKING: |
| 12 | + import matplotlib.colors |
12 | 13 | from matplotlib.figure import Figure as MplFigure |
13 | 14 | from numpy.typing import ArrayLike, NDArray |
14 | 15 |
|
15 | 16 | from cmap import Colormap |
16 | 17 |
|
| 18 | + from ._color import ColorLike |
| 19 | + from ._colormap import ColorStopsLike, Interpolation |
| 20 | + |
17 | 21 |
|
18 | 22 | def _ensure_cmap(cmap: Colormap | str) -> Colormap: |
19 | 23 | from cmap import Colormap |
@@ -498,6 +502,40 @@ def report(cm: Colormap, n: int = 256, uniform_space: str = "CAM02-UCS") -> Repo |
498 | 502 | # H -> hue composition |
499 | 503 |
|
500 | 504 |
|
| 505 | +def to_mpl( |
| 506 | + value: ColorStopsLike, |
| 507 | + /, |
| 508 | + *, |
| 509 | + name: str | None = None, |
| 510 | + identifier: str | None = None, |
| 511 | + category: str | None = None, |
| 512 | + interpolation: Interpolation | bool | None = None, |
| 513 | + under: ColorLike | None = None, |
| 514 | + over: ColorLike | None = None, |
| 515 | + bad: ColorLike | None = None, |
| 516 | + N: int = 256, |
| 517 | + gamma: float = 1.0, |
| 518 | +) -> matplotlib.colors.Colormap: |
| 519 | + """Convienence function to create a matplotlib colormap. |
| 520 | +
|
| 521 | + Arguments are the same as for [cmap.Colormap][]. This simply creates the |
| 522 | + colormap instance and returns the value of `to_matplotlib()`. |
| 523 | + """ |
| 524 | + from cmap import Colormap |
| 525 | + |
| 526 | + cm = Colormap( |
| 527 | + value, |
| 528 | + name=name, |
| 529 | + identifier=identifier, |
| 530 | + category=category, |
| 531 | + interpolation=interpolation, |
| 532 | + under=under, |
| 533 | + over=over, |
| 534 | + bad=bad, |
| 535 | + ) |
| 536 | + return cm.to_matplotlib(N=N, gamma=gamma) |
| 537 | + |
| 538 | + |
501 | 539 | if __name__ == "__main__": # pragma: no cover |
502 | 540 | import matplotlib.pyplot as plt |
503 | 541 |
|
|
0 commit comments