Skip to content

Instantly share code, notes, and snippets.

@ischurov
Created April 4, 2021 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ischurov/fb00906c5704ebdd56ff13d7e02583e4 to your computer and use it in GitHub Desktop.
Save ischurov/fb00906c5704ebdd56ff13d7e02583e4 to your computer and use it in GitHub Desktop.
How to use celluloid with streamlit
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
import streamlit.components.v1 as components
from celluloid import Camera
# Based on this recipe:
# https://discuss.streamlit.io/t/matplotlib-animation-in-streamlit-through-html-js/5587
with st.echo(code_location='below'):
st.title("Hello, World!")
"""
This is a test.
"""
x = np.linspace(0, 10, 500)
fig = plt.figure()
camera = Camera(fig)
for i in range(10):
plt.plot(x, np.sin(x + i))
plt.ylim(-2, 2)
camera.snap()
animation = camera.animate()
components.html(animation.to_jshtml(), height=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment