Skip to content

Commit 67e3679

Browse files
committed
Add detailed docstrings and examples for callbacks and figure modules; create new RST files for callbacks, figure plots, markers, and widgets
1 parent 0fd3d80 commit 67e3679

11 files changed

Lines changed: 116 additions & 24 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ although the scope is intentionally limited in the following ways:
1010
no `plt.imshow` or `plt.plot` – instead, you create a Figure object and call methods on it to add data
1111
and customize the plot. This is a deliberate choice to avoid the pitfalls of the stateful API.
1212

13-
python
14-
```
13+
```python
1514
import anyplotlib as apl
1615
import matplotlib.pyplot as plt
1716

@@ -43,10 +42,11 @@ environment that supports `AnyWidget`, including Jupyter notebooks, JupyterLab,
4342
the hood, `AnyWidget` uses a pure-JavaScript implementation of the widget protocol, which allows for fast rendering
4443
and interactivity.
4544

46-
**Disclaimer**: This project is in the early stages of development. Additionally many of the
47-
javascript code was optimized using LLM's. That being said, the javascript/python code is fairly minimal,
48-
and not too difficult to understand.
45+
## Getting Started
4946

47+
Install from PyPI:
48+
```bash
49+
pip install anyplotlib
50+
```
5051

51-
**Disclaimer #2**: Mostly this project is to see __if__ something like this is possible, it remains to be
52-
seen if this can be developed into a full-fledged plotting library. The hope is that this can be.
52+
See the [documentation](https://cssfrancis.github.io/anyplotlib/) for more information.

anyplotlib/callbacks.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
"""
2+
callbacks.py
3+
============
4+
5+
Lightweight two-class event system used by every plot object and widget.
6+
7+
:class:`CallbackRegistry`
8+
Per-object store of named callbacks. Every plot object and widget
9+
exposes ``on_changed``, ``on_release``, ``on_click``, and ``on_key``
10+
decorator methods that connect handlers through this registry.
11+
12+
:class:`Event`
13+
Immutable data-carrier passed to every callback. All keys in the
14+
raw JS payload are accessible as attributes (``event.zoom``,
15+
``event.cx``, etc.) in addition to the typed ``event_type``,
16+
``source``, and ``data`` fields.
17+
18+
Example
19+
-------
20+
.. code-block:: python
21+
22+
fig, ax = apl.subplots(1, 1)
23+
plot = ax.imshow(data)
24+
25+
@plot.on_release
26+
def on_settle(event):
27+
print(f"zoom={event.zoom:.2f} center=({event.center_x:.3f}, {event.center_y:.3f})")
28+
"""
29+
130
from __future__ import annotations
231
from dataclasses import dataclass, field
332
from typing import Any, Callable

anyplotlib/figure.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
"""
2+
figure.py
3+
=========
4+
5+
Top-level :class:`Figure` widget and the :func:`subplots` factory.
6+
7+
``Figure`` is the only ``anywidget.AnyWidget`` subclass in anyplotlib.
8+
It owns all traitlets and acts as the Python ↔ JavaScript bridge.
9+
Use :func:`subplots` (the recommended entry-point) or construct a
10+
``Figure`` directly and call :meth:`Figure.add_subplot` to attach data.
11+
12+
Example
13+
-------
14+
.. code-block:: python
15+
16+
import numpy as np
17+
import anyplotlib as apl
18+
19+
fig, axs = apl.subplots(1, 2, figsize=(800, 400))
20+
axs[0].imshow(np.random.standard_normal((128, 128)))
21+
axs[1].plot(np.sin(np.linspace(0, 6.28, 256)))
22+
fig
23+
"""
24+
125
from __future__ import annotations
226
import json, pathlib
327
import anywidget, numpy as np, traitlets

docs/api/callbacks.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Callbacks
2+
=========
3+
4+
.. automodule:: anyplotlib.callbacks
5+
:members:
6+
:undoc-members: False
7+
:show-inheritance:
8+
:member-order: bysource
9+

docs/api/figure_plots.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Figure Plots
2+
============
3+
4+
.. automodule:: anyplotlib.figure_plots
5+
:members:
6+
:undoc-members: False
7+
:show-inheritance:
8+
:member-order: bysource
9+

docs/api/index.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ API Reference
22
=============
33

44
.. toctree::
5-
:maxdepth: 1
5+
:maxdepth: 2
66

77
figure
8-
8+
figure_plots
9+
markers
10+
widgets
11+
callbacks

docs/api/markers.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Markers
2+
=======
3+
4+
.. automodule:: anyplotlib.markers
5+
:members:
6+
:undoc-members: False
7+
:show-inheritance:
8+
:member-order: bysource
9+

docs/api/widgets.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Widgets
2+
=======
3+
4+
.. automodule:: anyplotlib.widgets
5+
:members:
6+
:undoc-members: False
7+
:show-inheritance:
8+
:member-order: bysource
9+

docs/conf.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,10 @@
8686
"logo": {
8787
"image_light": "_static/anyplotlib.svg",
8888
"image_dark": "_static/anyplotlib.svg",
89-
"text": "anyplotlib",
89+
"text": "anyplotlib"
9090
},
91-
"switcher": {
92-
"json_url": f"{_base}switcher.json",
93-
"version_match": _docs_version,
94-
},
95-
"navbar_end": ["version-switcher", "navbar-icon-links"],
96-
"show_toc_level": 2,
91+
"navbar_end": ["navbar-icon-links"],
92+
"show_toc_level": 2
9793
}
9894

9995
# -- autodoc options ---------------------------------------------------------

docs/getting_started.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ Getting Started
44
Installation
55
------------
66

7-
Clone the repository and install with ``uv`` (or pip)::
7+
Install via pip from PyPI (recommended)::
88

9-
git clone https://github.com/your-org/anyplotlib.git
9+
pip install anyplotlib
10+
11+
Or clone the repository and install from source::
12+
13+
git clone https://github.com/CSSFrancis/anyplotlib.git
1014
cd anyplotlib
11-
uv sync # installs the project + all dependencies
15+
uv sync # or `pip install -e .`
1216

1317
Quick start
1418
-----------

0 commit comments

Comments
 (0)