Skip to content
Snippets Groups Projects

Removed streamlit and inflect

Merged Michiel Cottaar requested to merge remove-streamlit into master
6 files
+ 0
169
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 0
36
# Michiel's minimal example of a streamlit browser-based GUI
# run using:
# streamlit run <script name>
import streamlit as st
import numpy as np
import string
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 101)
model = st.sidebar.selectbox('function to plot', ['polynomial', 'sinusoidal'])
placholder = st.empty()
if model == 'polynomial':
degree = st.sidebar.slider("polynomial degree", 1, 10)
vars = list(string.ascii_lowercase[:degree])
terms = []
y = 0
for idx, var in enumerate(vars):
if idx == 0:
terms.append(var)
elif idx == 1:
terms.append(f"{var} x")
else:
terms.append(f"{var} x^{idx}")
value = st.slider(var, -10., 10., 1. if idx == len(vars) - 1 else 0.)
y += value * x ** idx
equation = " + ".join(terms)
elif model == 'sinusoidal':
equation = "A sin(\omega x + \phi)"
A = st.slider("Amplitude (A)", -10., 10., 1.)
omega = st.slider("Frequency (omega)", -10., 10., np.pi)
phi = st.slider("phase (phi)", -10., 10., 0.)
y = A * np.sin(omega * x + phi)
placholder.write(f"${equation}$")
fig = plt.figure()
plt.plot(x, y)
st.write(fig)
\ No newline at end of file
Loading