Hi all,
I have data representing a bunch of points in 2D. They move in time. They’re each one of three colors, and they could change to one of the other colors over time. Is there a nice way to animate this with streamlit? Right now, I’m using matplotlib’s scatterplot, with a loop that updates the positions and colors of each point. I didn’t quite see how to do it with one of the more efficient streamlit things like Altair or Pandas, but hopefully I’m missing something obvious. I can easily store the data however would be most useful (numpy array, pandas dataframe, lots of lists, whatever).
That first one is almost exactly what I need. Is there a way to delete the old data? I want this to end up looking like a specific number of points are moving around.
FWIW, I tried the animated line chart code and couldn’t get it to work. Streamlit did not give any errors … but I also didn’t see an animated line chart.
You could do something like this, let me know if this works for you
import streamlit as st
import altair as alt
from vega_datasets import data
import time
source = data.cars()
chart = st.empty()
for i in source.index:
data_to_be_added = source.iloc[0: i + 1, :]
x = alt.Chart(data_to_be_added).mark_circle(size=i * 10).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()
time.sleep(0.2)
chart.altair_chart(x)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.