streamlit-testGenius/streamlit_app.py

41 lines
1.1 KiB
Python
Raw Normal View History

2020-11-03 14:29:22 +08:00
import altair as alt
2023-11-03 03:32:17 +08:00
import numpy as np
2020-11-03 14:29:22 +08:00
import pandas as pd
import streamlit as st
"""
# Welcome to Streamlit!
2023-11-03 03:32:17 +08:00
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
2020-11-03 14:54:01 +08:00
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
2020-11-03 14:29:22 +08:00
In the meantime, below is an example of what you can do with just a few lines of code:
"""
2023-11-03 03:32:17 +08:00
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
indices = np.linspace(0, 1, num_points)
theta = 2 * np.pi * num_turns * indices
radius = indices
x = radius * np.cos(theta)
y = radius * np.sin(theta)
df = pd.DataFrame({
"x": x,
"y": y,
"idx": indices,
"rand": np.random.randn(num_points),
})
st.altair_chart(alt.Chart(df, height=700, width=700)
.mark_point(filled=True)
.encode(
x=alt.X("x", axis=None),
y=alt.Y("y", axis=None),
color=alt.Color("idx", legend=None, scale=alt.Scale()),
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
))