Skip to content

Commit 974de61

Browse files
authored
Improve docs (#15)
* update docs * add docs of sphinx-gallery * fixes
1 parent f855dc8 commit 974de61

File tree

7 files changed

+135
-37
lines changed

7 files changed

+135
-37
lines changed

doc/commandline.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Command Line Usage
2+
3+
**recording interactions**
4+
To record a json file for later playback:
5+
```bash
6+
python -m mpl_playback.record example_file.py -figures fig --output example_playback.json
7+
```
8+
9+
This will launch example_file.py and record any interactions with the object named `fig`. Then it will be saved to `example_playback.json`. However, the output argument is optional, if not given then the name will be `example_file-playback.json`
10+
11+
**playback interactions in a gif**
12+
To play back the file you must pass both the original python file and the recording json file. You can optionally pass names for the output gif(s) with the `--output` argument, or allow the names to be chosen automatically. 1 gif will be created for each figure that was recorded.
13+
14+
```bash
15+
python -m mpl_playback.playback example_file.py example_playback.json
16+
```

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3434
# ones.
3535
extensions = [
36+
"myst_nb",
3637
"sphinx_gallery.gen_gallery",
3738
]
3839

doc/contributing.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Contributing
2+
3+
Thanks for thinking of a way to help improve this library! Remember that contributions come in all shapes and sizes beyond writing bug fixes. Contributing to [documentation](#documentation), opening new [issues](https://github.com/ianhi/mpl-playback/issues) for bugs, asking for clarification on things you find unclear, and requesting new features, are all super valuable contributions.
4+
5+
## Code Improvements
6+
7+
All development for this library happens on GitHub at [mpl-playback](https://github.com/ianhi/mpl-playback). We recommend you work with a [Conda](https://www.anaconda.com/products/individual) environment (or an alternative virtual environment like [`venv`](https://docs.python.org/3/library/venv.html)).
8+
9+
```bash
10+
git clone <your fork>
11+
cd mpl-playback
12+
mamba env create -n mpl-playback python matplotlib -c conda-forge
13+
conda activate mpl-playback
14+
pip install pre-commit
15+
pre-commit install
16+
```
17+
18+
The `mamba env create` command installs all Python packages that are useful when working on the source code of `mpl_playback` and its documentation. You can also install these packages separately:
19+
20+
```bash
21+
pip install -e .[doc]
22+
```
23+
24+
The {command}`-e .` flag installs the `mpl_playback` folder in ["editable" mode](https://pip.pypa.io/en/stable/cli/pip_install/#editable-installs) and {command}`[dev]` installs the [optional dependencies](https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#optional-dependencies) you need for developing `mpl_playback`.
25+
26+
### Seeing your changes
27+
28+
If you are working in a Jupyter Notebook, then in order to see your code changes you will need to either:
29+
30+
- Restart the Kernel every time you make a change to the code.
31+
- Make the function reload from the source file every time you run it by using [autoreload](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html), e.g.:
32+
33+
```python
34+
%load_ext autoreload
35+
%autoreload 2
36+
from mpl_playback import ....
37+
```
38+
39+
### Working with Git
40+
41+
Using Git/GitHub can confusing (<https://xkcd.com/1597>), so if you're new to Git, you may find it helpful to use a program like [GitHub Desktop](https://desktop.github.com) and to follow a [guide](https://github.com/firstcontributions/first-contributions#first-contributions).
42+
43+
Also feel free to ask for help/advice on the relevant GitHub [issue](https://github.com/ianhi/mpl-playback/issues).
44+
45+
## Documentation
46+
47+
Our documentation on Read the Docs ([mpl-playback.rtfd.io](https://mpl-playback.readthedocs.io)) is built with [Sphinx](https://www.sphinx-doc.org) from the notebooks in the `docs` folder. It contains both Markdown files and Jupyter notebooks.
48+
49+
If you open the `index.html` file in your browser you should now be able to see the rendered documentation.
50+
51+
Alternatively, you can use [sphinx-autobuild](https://github.com/executablebooks/sphinx-autobuild) to continuously watch source files for changes and rebuild the documentation for you. Sphinx-autobuild will be installed automatically by the above `pip` command, so all you need to do is run:
52+
53+
```bash
54+
tox -e doclive
55+
```
56+
57+
In a few seconds your web browser should open up the documentation. Now whenever you save a file the documentation will automatically regenerate and the webpage will refresh for you!

doc/index.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.. mpl-playback documentation master file, created by
2+
sphinx-quickstart on Mon Jan 11 19:21:27 2021.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
# Welcome to mpl-playback's documentation!
7+
8+
A library to record and then playback user interactions with a Matplotlib
9+
figure. Also integrates with [sphinx-gallery](https://sphinx-gallery.github.io/stable/index.html)
10+
by providing a custom scraper so docs using widgets will render showing the interactions.
11+
See this in action in the :doc:`Gallery <gallery/index>`.
12+
13+
Inspired by discussions here: https://github.com/matplotlib/matplotlib/issues/19222
14+
15+
## Installation
16+
17+
```bash
18+
pip install mpl-playback
19+
```
20+
21+
```{note}
22+
If you are using for your sphinx-gallery docs build you should pin the version of `mpl-playback`.
23+
```
24+
25+
### Q: Should you use this?
26+
A: Depends on what you want. For one off gifs of interactions it's almost certainly easier to just record your screen to make a gif. But if you want integration with `sphinx-gallery` then this is currently the only option.
27+
28+
29+
30+
```{toctree}
31+
:maxdepth: 3
32+
33+
gallery/index
34+
commandline
35+
sphinx-gallery
36+
contributing
37+
```
38+
39+
### Indices and Tables
40+
41+
- {ref}`genindex`
42+
- {ref}`modindex`
43+
- {ref}`search`

doc/index.rst

Lines changed: 0 additions & 37 deletions
This file was deleted.

doc/sphinx-gallery.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Sphinx-gallery integration
2+
3+
4+
`mpl-playback` provides a custom [sphinx-gallery scraper](https://sphinx-gallery.github.io/stable/advanced.html#write-a-custom-image-scraper) which allows you automatically generate gifs for your interactive maptlotlib plots in your sphinx gallery. This custom scraper will generate a gif if there is a playback json file available, and otherwise will fall back to the default matplotlib scraper.
5+
6+
To enable the custom scraper add the following to your `conf.py`
7+
8+
9+
```python
10+
from mpl_playback.scraper import matplotlib_scraper
11+
sphinx_gallery_conf = {
12+
# ... the rest of your normal config
13+
"image_scrapers": (matplotlib_scraper),
14+
}
15+
```
16+
17+
then the scraper will automatically pick up any playback files that are in the same directory as the examples.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ python_requires = >=3.8
3535
docs =
3636
Sphinx>=1.5
3737
furo
38+
myst_nb
3839
sphinx-copybutton
3940
sphinx_gallery
4041

0 commit comments

Comments
 (0)