8000 docs: update docs and use api-autonav by tlambert03 · Pull Request #93 · pyapp-kit/cmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: update docs and use api-autonav #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 15, 2025
Merged
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- id: pretty-format-json
Expand Down
3 changes: 0 additions & 3 deletions docs/api/color.md

This file was deleted.

9 changes: 0 additions & 9 deletions docs/api/colormap.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/catalog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cmap = Colormap('viridis')
`matplotlib.colors.Colormap` instance, you may call
[`.to_mpl()`][cmap.Colormap.to_matplotlib].

See the [Colormap API docs](../api/colormap.md) for details.
See the [Colormap API docs][cmap.Colormap] for details.

<!--
With that object you can do things like:
Expand Down
13 changes: 9 additions & 4 deletions docs/colormaps.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Colormaps

The `cmap.Colormap` type represents a colormap.
The [`cmap.Colormap`][cmap.Colormap] type represents a colormap.

Also known as a LUT (look-up table), a colormap is a mapping from a scalar value to a color. Colormaps are used in a variety of contexts, including image processing, data visualization, and scientific visualization. The `cmap` library provides a [number of built-in colormaps](catalog/index.md), including all of the colormaps in matplotlib, napari, vispy, and more.
Also known as a LUT (look-up table), a colormap is a mapping from a scalar value
to a color. Colormaps are used in a variety of contexts, including image
processing, data visualization, and scientific visualization. The `cmap`
library provides a [number of built-in colormaps](catalog/index.md), including
all of the colormaps in matplotlib, cmocean, colorbrewer, colorcet, crameri, and
more.

```python
from cmap import Colormap
Expand All @@ -15,7 +20,7 @@ cm = Colormap('viridis')

The following objects can be interpreted as a colormap, and used as the first argument
to the [`cmap.Colormap`][] constructor; `cmap` refers to these objects collectively as
"`ColormapLike`". Briefly, valid arguments are of type:
["`ColormapLike`"][cmap.ColormapLike]. Briefly, valid arguments are of type:

- [⬇️ `str`](#str)
- [⬇️ `Iterable[ColorLike | tuple[float, ColorLike]]`](#iterablecolorlike-tuple) *(see [`ColorLike`](colors.md#colorlike-objects))*
Expand Down Expand Up @@ -300,7 +305,7 @@ external visualization libraries. To that end, `cmap.Colormap` provides
`to_<libname>()` methods for a number of libraries:

!!!tip
Some of these methods take additional arguments, see [Colormap API](api/colormap.md)
Some of these methods take additional arguments, see [Colormap API][cmap.Colormap]
for details.

- [matplotlib](https://matplotlib.org/)
Expand Down
16 changes: 10 additions & 6 deletions 8000 docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Namespaces are directories in the `src/cmap/data` folder.

- If the colormap is part of known broader collection (e.g., `cet`, `cmocean`,
`colorbrewer`, etc.), please check to see whether the collection already
exists in the `cmap/data` directory. If so, please extend that collection.
If not, please create a new namespace and directory for that collection.
exists in the [`cmap/data`
directory](https://github.com/pyapp-kit/cmap/tree/main/src/cmap/data). If so,
please extend that collection. If not, please create a new namespace and
directory for that collection.
- If you would like to contribute a colormap that doesn't nicely fit into an
broader collection of colormaps (regardless of whether that collection exists
in `cmap`), please contribute to the `cmap/contrib` namespace.
Expand All @@ -24,7 +26,7 @@ Once you have picked a namespace:
in the `record.json` file. The key should be the name of the colormap, and
the value should be an object with the following keys:
- `data`: either a direct
[`ColormapLike` data](https://cmap-docs.readthedocs.io/en/stable/colormaps/#colormaplike-objects)
[`ColormapLike` data](colormaps.md#colormaplike-objects)
entry, such as an array of RGB values; or a
string pointing to the python-path of colormap data in the form of
`cmap.data.<namespace>:<colormap>`.
Expand Down Expand Up @@ -57,8 +59,10 @@ Once you have picked a namespace:
]
```

**It may be helpful to look at existing folders and files in the
`cmap/data` directory for examples of how to structure the data.**
!!!tip
It may be helpful to look at existing folders and files in the
[`cmap/data` directory](https://github.com/pyapp-kit/cmap/tree/main/src/cmap/data)
for examples of how to structure the data

When opening a PR, please include a screenshot of the colormap, along
with a brief description of the colormap design and its intended use.
Expand All @@ -74,7 +78,7 @@ with a brief description of the colormap design and its intended use.
## How can I add support for exporting to another colormap format?

cmap [exports to a variety of known third-party colormap
formats](https://cmap-docs.readthedocs.io/en/latest/colormaps/#usage-with-external-visualization-libraries).
formats](colormaps.md#usage-with-external-visualization-libraries).

If you are the author (or user) of a library that consumes colormaps, and you
would like to have a `to_your_lib()` function in `cmap`, we welcome
Expand Down
16 changes: 8 additions & 8 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Overview

`cmap` is a work-in-progress colormap library for python, providing all of the
colormaps in matplotlib, vispy, cmocean, (and more), with no dependencies beyond
numpy.
`cmap` is a colormap library for python, providing all of the colormaps in
matplotlib, vispy, cmocean, (and more), with no dependencies beyond numpy.

## Purpose

Mapping scalar values to colors is a very common procedure in scientific
visualization; as such, many visualization libraries (e.g. matplotlib, vispy,
napari, etc...) have some need for and some internal representation of colors
pygfx, etc...) have some need for and some internal representation of colors
and colormaps.

!!!question "Don't we already have this?"
Expand All @@ -29,20 +28,21 @@ and colormaps.
beyond numpy. (by "applying" here, we mean converting an array of scalar
values to an array of RGBA values)
3. Provide an API for converting colormaps to the native format for a variety of
third party libraries (currently including, matplotlib, napari, vispy, pygfx,
bokeh, plotly, altair, and more)
third party libraries (such as matplotlib, napari, vispy, pygfx,
bokeh, plotly, altair,
[and more](https://github.com/pyapp-kit/cmap/blob/main/src/cmap/_external.py))

## Colormaps

For a complete list of available colormaps, see the [Colormaps
catalog](catalog/index.md). You can also use the search bar at the top to search
for a specific colormap.

For details on using the `cmap.Colormap` object, see [Colormaps](colormaps.md).
For details on using the [`cmap.Colormap`][cmap.Colormap] object, see [Colormaps](colormaps.md).

## Colors

This library also offers a simple `cmap.Color` object. It can cast a variety of
This library also offers a simple [`cmap.Color`][cmap.Color] object. It can cast a variety of
inputs (including strings, tuples/lists, arrays, integers) to an RGBA color
representation, and offers some basic conversions. See [Colors](colors.md) for
details
17 changes: 14 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ nav:
- Colors: colors.md
- Colormaps: colormaps.md
- Colormap Catalog: catalog/
- API: api/
- FAQ: faq.md

theme:
Expand Down Expand Up @@ -68,7 +67,11 @@ hooks:
plugins:
- search:
separator: '[\s\-\_,:!=\[\]()"/]+|(?!\b)(?=[A-Z][a-z])|\.(?!\d)|&[lg]t;'
- autorefs
- autorefs:
resolve_closest: true
- api-autonav:
modules: ['src/cmap']
exclude: ['cmap.data']
- literate-nav:
implicit_index: true
nav_file: SUMMARY.md
Expand All @@ -89,7 +92,7 @@ plugins:
- mkdocstrings:
handlers:
python:
import:
inventories:
- https://docs.python.org/3/objects.inv
- https://numpy.org/doc/stable/objects.inv
options:
Expand All @@ -105,6 +108,14 @@ plugins:
docstring_section_style: list
merge_init_into_class: true

filters: ['(__call__|^[^_])']
heading_level: 1
parameter_headings: true
separate_signature: true
show_symbol_type_heading: true
show_symbol_type_toc: true
summary: true

extra_css:
- stylesheets/extra.css

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ docs = [
'imageio',
'mkdocs-gen-files',
'mkdocs-literate-nav',
'mkdocs-api-autonav',
'mkdocs-material',
'mkdocs-minify-plugin',
'mkdocs',
Expand Down
7 changes: 5 additions & 2 deletions src/cmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
__version__ = "uninstalled"


from ._color import HSLA, HSVA, RGBA, RGBA8, Color
from ._colormap import Colormap, ColorStops
from ._color import HSLA, HSVA, RGBA, RGBA8, Color, ColorLike
from ._colormap import Colormap, ColormapLike, ColorStop, ColorStops

if TYPE_CHECKING:
from ._catalog import CatalogItem
Expand Down Expand Up @@ -69,6 +69,9 @@ def resolve(self, name: str) -> str:
"Catalog",
"CatalogItem",
"Color",
"ColorLike",
"ColorStop",
"ColorStops",
"Colormap",
"ColormapLike",
]
13 changes: 7 additions & 6 deletions src/cmap/_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from _typeshed import FileDescriptorOrPath
from typing_extensions import NotRequired, Required, TypeAlias, TypedDict

from ._colormap import ColorStopsLike, Interpolation
from ._colormap import ColormapLike, Interpolation

Category: TypeAlias = Literal[
"sequential", "diverging", "cyclic", "qualitative", "miscellaneous"
Expand Down Expand Up @@ -78,9 +78,10 @@ class CatalogItem:

Attributes
----------
data: ColorStopsLike
data: ColormapLike
Any object that can be passed to `Colormap` to create a colormap.
https://cmap-docs.readthedocs.io/en/latest/colormaps/#colormaplike-objects
See [ColormapLike objects](../../colormaps.md#colormaplike-objects) for more
information.
name: str
The (short) name of the colormap, e.g. "viridis".
category: str
Expand Down Expand Up @@ -118,7 +119,7 @@ class CatalogItem:
The color to use for bad values.
"""

data: ColorStopsLike
data: ColormapLike
name: str
category: Category
license: str = "UNKNOWN"
Expand Down Expand Up @@ -208,11 +209,11 @@ def _build_catalog(records: Iterable[FileDescriptorOrPath]) -> CatalogDict:


class Catalog(Mapping[str, "CatalogItem"]):
"""Catalog of available colormaps.
"""Runtime representation of catalog of available colormaps.

Parameters
----------
root : Path, optional
data_root : Path, optional
Path to the root of the data directory, by default uses the `cmap.data` folder.
record_pattern : str, optional
Glob pattern to use to find record files, by default "record.json".
Expand Down
Loading
Loading
0