-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.py
42 lines (30 loc) · 849 Bytes
/
example2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Requires `pip install matplotlib numpy`
import matplotlib.pyplot as plt
import numpy as np
import streamlit as st
from pydantic import BaseModel
from pydantic import Field
from statelit import StateManager
class AppState(BaseModel):
class Config:
@staticmethod
def streamlit_label_generator(x):
return x.replace("_", " ").title()
seed: int = 372193
size: int = 10_000
mu: float = 5.0
sigma: float = 5.0
bins: int = 100
log: bool = False
state_manager = StateManager(AppState)
with st.sidebar:
state = state_manager.form()
with st.expander("State"):
state_manager.text_area()
np.random.seed(state.seed)
arr = np.random.normal(state.mu, state.sigma, size=state.size)
if state.log:
arr = np.log(arr)
fig, ax = plt.subplots()
ax.hist(arr, bins=state.bins)
st.pyplot(fig)