Skip to content

Improve docs for to_jshtml() #21081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/api/animation_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ to. If you do not hold a reference to the `Animation` object, it (and
hence the timers) will be garbage collected which will stop the
animation.

To save an animation to disk use `Animation.save` or `Animation.to_html5_video`
To save an animation use `Animation.save`, `Animation.to_html5_video`,
or `Animation.to_jshtml`.

See :ref:`ani_writer_classes` below for details about what movie formats are
supported.
Expand Down
15 changes: 14 additions & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,20 @@ def to_html5_video(self, embed_limit=None):
return 'Video too large to embed.'

def to_jshtml(self, fps=None, embed_frames=True, default_mode=None):
"""Generate HTML representation of the animation"""
"""
Generate HTML representation of the animation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One major usecase is to embed the animation into a jupyter notebook. Maybe that should be mentioned. See here for an example: https://github.com/timhoffm/euroscipy2019-using-matplotlib/blob/master/06_Animations.ipynb

Parameters
----------
fps : int, optional
Movie frame rate (per second). If not set, the frame rate from
the animation's frame interval.
embed_frames : bool, optional
Copy link
Member

@timhoffm timhoffm Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick look: If embed_frames is True, the frame image data are inlined into the HTML. Otherwise they are written to separate files. Given that the data is read back in, I'm wondering if that option does make any sense (or works if set to false at all), becuase that would imply we still need access to the temporary directory. - This should probably be checked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have bandwidth to check at the moment - if someone else wants to feel free, otherwise I'd advocate merging this as an improvement over what was there before.

default_mode : str, optional
What to do when the animation ends. Must be one of ``{'loop',
'once', 'reflect'}``. Defaults to ``'loop'`` if ``self.repeat``
is True, otherwise ``'once'``.
"""
if fps is None and hasattr(self, '_interval'):
# Convert interval in ms to frames per second
fps = 1000 / self._interval
Expand Down