build a streamlit app for calculating sin and cos function and plot it. Make sure it compiles and runs
Drop files here
or click to upload
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
st.title("Trigonometric Functions Calculator")
# Create input for range
x_min = st.slider("Select minimum x value", -10.0, 0.0, -2*np.pi)
x_max = st.slider("Select maximum x value", 0.0, 10.0, 2*np.pi)
points = st.slider("Number of points", 10, 1000, 100)
# Generate x values
x = np.linspace(x_min, x_max, points)
# Calculate sin and cos
sin_y = np.sin(x)
cos_y = np.cos(x)
# Create the plot
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(x, sin_y, label='sin(x)')
ax.plot(x, cos_y, label='cos(x)')
ax.grid(True)
ax.legend()
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Sin and Cos Functions')
# Display the plot
st.pyplot(fig)
# Show some values in a table
if st.checkbox("Show values in table"):
df_values = {
'x': x,
'sin(x)': sin_y,
'cos(x)': cos_y
}
st.dataframe(df_values)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?