Skip to main content

Add animations to revealjs presentations from Python code-blocks.

Project description

PyFragments

Add animated figures to your Quarto presentations.

Install

pip install pyfragments

Example

A Revealjs presentation created with Quarto, which displays an animated matplotlib figure:

Animated figure

This is created with the following code, in a Quarto .qmd file.

---
format: revealjs
---

## Example of an animated figure

Move to the next slide to see the transitions.

```{python}
# | output: asis
import matplotlib.pyplot as plt
from pyfragments import AnimatedFigure

with AnimatedFigure() as ani:
    plt.xlim(0, 10)
    plt.ylim(0, 10)
    for i in range(10):
        with ani.fragment():
            plt.scatter(i, i)

```

SVG example

To use SVG images, each call to a matplotlib function must include a group id (gid) with a value of .fragment.

Note: it is important to set embed-resources: true in the YAML options.

---
format: revealjs
embed-resources: true
---

# 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(10):
    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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfragments-0.4.1.tar.gz (51.0 kB view details)

Uploaded Source

Built Distribution

pyfragments-0.4.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pyfragments-0.4.1.tar.gz.

File metadata

  • Download URL: pyfragments-0.4.1.tar.gz
  • Upload date:
  • Size: 51.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyfragments-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ca176203aba48f9e4ba479cc654c3bf06a9daaa8b7e1a2ab283b34ee35e9bad6
MD5 30076aaf99319b6f57e93b6d3cb36752
BLAKE2b-256 19352fe04f828508f35a80cd52004fda2a771055c164f1d68ecfd6c06350db98

See more details on using hashes here.

File details

Details for the file pyfragments-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pyfragments-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyfragments-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10eddb811bb8ef4b1ee01f854d2e32af00d98fa03b5e2ba51a92976f682f36a7
MD5 8eeb84462b320c509f91a426f58f2dc3
BLAKE2b-256 25d56ef378cfbe9cfb833c0cbb2598d5ea59efc6e111c197080e4dba37480285

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page