pyfragments
Add animations to revealjs presentations from Python code-blocks.
Example
A Revealjs presentation created with Quarto, which shows matplotlib figure animated with fragments (i.e., moving to the next slide):
This is created with the following code,
in a Quarto .qmd file.
---
format: revealjs
---
## Animated scatterplot
Move to the next slide to see the transitions.
```{python}
# | output: asis
import matplotlib.pyplot as plt
from pyfragments.png import AnimatedFigure
with AnimatedFigure() as ani:
plt.xlim(-1, 3)
plt.ylim(-1, 3)
for i in range(3):
with ani.fragment():
plt.scatter(i, i, s=200)
```
Docs
See the demo in GitHub Pages.
To change the order of fragments,
or make different elements appear at the same time,
use ani.fragment(<num>):
with ani.fragment(2): # appears second
ax.scatter(...)
with ani.fragment(1): # appears first
ax.scatter(...)
with ani.fragment(2): # appears second
ax.scatter(...)
SVG
To use SVG images,
each call to a matplotlib function must include a group id (gid) with a value of .fragment.
---
format: revealjs
---
# Example of an animated figure
## Animated scatterplot
Move to the next slide to see the transitions.
```{python}
from matplotlib.figure import Figure
from pyfragments.svg import animate
fig = Figure()
ax = fig.add_subplot()
for i in range(3):
ax.scatter(i, i, gid=".fragment")
animate(fig)
```
To change the order of fragments,
or make different elements appear at the same time,
use .fragment-<num>:
ax.scatter(..., gid=".fragment-2") # appears second
ax.scatter(..., gid=".fragment-1") # appears first
ax.scatter(..., gid=".fragment-2") # appears second
To allow animation of images,
such as with ax.imshow,
it is important to disable image.composite_image:
import matplotlib
matplotlib.rc("image", composite_image=False)
Install
Using pixi, install from PyPI with:
pixi add --pypi pyfragments
or install the latest development version from GitHub with:
pixi add --pypi pyfragments@https://github.com/maurosilber/pyfragments.git
Otherwise,
use pip or your pip-compatible package manager:
pip install pyfragments # from PyPI
pip install git+https://github.com/maurosilber/pyfragments.git # from GitHub
Development
This project is managed by pixi. You can install it for development using:
git clone https://github.com/maurosilber/pyfragments
cd pyfragments
pixi run pre-commit-install
Pre-commit hooks are used to lint and format the project.
Testing
Run tests using:
pixi run test
Publishing to PyPI
When a tagged commit is pushed to GitHub,
the GitHub Action defined in .github/workflows/ci.yml
builds and publishes the package to PyPI.
Tag a commit and push the tags with:
git tag <my-tag>
git push --tags
Trusted publishing must be enabled once in PyPI Publishing. Fill the following values in the form:
PyPI Project Name: pyfragments
Owner: maurosilber
Repository name: pyfragments
Workflow name: ci.yml
Environment name: pypi
Metadata
Release files for pyfragments 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyfragments-0.5.0.tar.gz | 5.0 kB | Without provenance | Details for pyfragments-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyfragments-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for pyfragments-0.5.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / pyfragments-0.5.0.tar.gz
| Download URL | pyfragments-0.5.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e299a24914d4dad16e40971a6b9fe553579297160d1549ffb87e0a84082cd180
|
|
BLAKE2b-256 checksum How to use checksums |
432d3b82456311def49b6631638e80d62f4b0bdad6486bcfb78b2e94d9e065ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pyfragments-0.5.0-py3-none-any.whl
| Download URL | pyfragments-0.5.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
887e1b067e833ee11c84df4f3b38141eab54964d52d1100f83d31b7a25283b9c
|
|
BLAKE2b-256 checksum How to use checksums |
d553e4af70e5442492435f86762fdea76396e2ea9bd2bc6d3ef6134ace3ea0d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pyfragments 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.