pyfragments


Namepyfragments JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryAdd animations to revealjs presentations from Python code-blocks.
upload_time2024-05-20 15:34:12
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2023 Mauro Silberberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords quarto revealjs presentation fragments animations matplotlib
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyFragments

Add animated figures to your [Quarto](https://quarto.org) presentations.

## Install

```
pip install pyfragments
```

## Example

A [Revealjs](https://quarto.org/docs/presentations/revealjs/)
presentation created with Quarto,
which displays an *animated* matplotlib figure:

![Animated figure](https://raw.githubusercontent.com/maurosilber/pyfragments/main/docs/animated_figure.gif)

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

````qmd
---
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.

````qmd
---
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>`:

```python
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`:

```python
import matplotlib

matplotlib.rc("image", composite_image=False)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyfragments",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "quarto, revealjs, presentation, fragments, animations, matplotlib",
    "author": null,
    "author_email": "Mauro Silberberg <maurosilber@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/19/35/2fe04f828508f35a80cd52004fda2a771055c164f1d68ecfd6c06350db98/pyfragments-0.4.1.tar.gz",
    "platform": null,
    "description": "# PyFragments\n\nAdd animated figures to your [Quarto](https://quarto.org) presentations.\n\n## Install\n\n```\npip install pyfragments\n```\n\n## Example\n\nA [Revealjs](https://quarto.org/docs/presentations/revealjs/)\npresentation created with Quarto,\nwhich displays an *animated* matplotlib figure:\n\n![Animated figure](https://raw.githubusercontent.com/maurosilber/pyfragments/main/docs/animated_figure.gif)\n\nThis is created with the following code,\nin a Quarto `.qmd` file.\n\n````qmd\n---\nformat: revealjs\n---\n\n## Example of an animated figure\n\nMove to the next slide to see the transitions.\n\n```{python}\n# | output: asis\nimport matplotlib.pyplot as plt\nfrom pyfragments import AnimatedFigure\n\nwith AnimatedFigure() as ani:\n    plt.xlim(0, 10)\n    plt.ylim(0, 10)\n    for i in range(10):\n        with ani.fragment():\n            plt.scatter(i, i)\n\n```\n````\n\n## SVG example\n\nTo use SVG images,\neach call to a `matplotlib` function must include a group id (`gid`) with a value of `.fragment`.\n\nNote: it is important to set `embed-resources: true`\nin the YAML options.\n\n````qmd\n---\nformat: revealjs\nembed-resources: true\n---\n\n# Example of an animated figure\n\n## Animated scatterplot\n\nMove to the next slide to see the transitions.\n\n```{python}\nfrom matplotlib.figure import Figure\nfrom pyfragments.svg import animate\n\nfig = Figure()\nax = fig.add_subplot()\nfor i in range(10):\n    ax.scatter(i, i, gid=\".fragment\")\nanimate(fig)\n```\n````\n\nTo change the order of fragments,\nor make different elements appear at the same time,\nuse `.fragment-<num>`:\n\n```python\nax.scatter(..., gid=\".fragment-2\")  # appears second\nax.scatter(..., gid=\".fragment-1\")  # appears first\nax.scatter(..., gid=\".fragment-2\")  # appears second\n```\n\nTo allow animation of images,\nsuch as with `ax.imshow`,\nit is important to disable `image.composite_image`:\n\n```python\nimport matplotlib\n\nmatplotlib.rc(\"image\", composite_image=False)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Mauro Silberberg  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Add animations to revealjs presentations from Python code-blocks.",
    "version": "0.4.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/maurosilber/pyfragments/issues",
        "Homepage": "https://github.com/maurosilber/pyfragments"
    },
    "split_keywords": [
        "quarto",
        " revealjs",
        " presentation",
        " fragments",
        " animations",
        " matplotlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25d56ef378cfbe9cfb833c0cbb2598d5ea59efc6e111c197080e4dba37480285",
                "md5": "8eeb84462b320c509f91a426f58f2dc3",
                "sha256": "10eddb811bb8ef4b1ee01f854d2e32af00d98fa03b5e2ba51a92976f682f36a7"
            },
            "downloads": -1,
            "filename": "pyfragments-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8eeb84462b320c509f91a426f58f2dc3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6948,
            "upload_time": "2024-05-20T15:34:11",
            "upload_time_iso_8601": "2024-05-20T15:34:11.749459Z",
            "url": "https://files.pythonhosted.org/packages/25/d5/6ef378cfbe9cfb833c0cbb2598d5ea59efc6e111c197080e4dba37480285/pyfragments-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19352fe04f828508f35a80cd52004fda2a771055c164f1d68ecfd6c06350db98",
                "md5": "30076aaf99319b6f57e93b6d3cb36752",
                "sha256": "ca176203aba48f9e4ba479cc654c3bf06a9daaa8b7e1a2ab283b34ee35e9bad6"
            },
            "downloads": -1,
            "filename": "pyfragments-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "30076aaf99319b6f57e93b6d3cb36752",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 51039,
            "upload_time": "2024-05-20T15:34:12",
            "upload_time_iso_8601": "2024-05-20T15:34:12.705596Z",
            "url": "https://files.pythonhosted.org/packages/19/35/2fe04f828508f35a80cd52004fda2a771055c164f1d68ecfd6c06350db98/pyfragments-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-20 15:34:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "maurosilber",
    "github_project": "pyfragments",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pyfragments"
}
        
Elapsed time: 0.30631s