jpoptum's picture
Rename simluation.py to app.py
febe850
raw
history blame
1.31 kB
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Define the time variable
t = np.linspace(0, 2*np.pi, 100)
# Create a meshgrid for the x and y axes
x, y = np.meshgrid(np.linspace(-1, 1, 100), np.linspace(-1, 1, 100))
# Define the amplitudes and frequencies of the waves
amp_e = st.sidebar.slider('Amplitude of Electric Field', min_value=0.0, max_value=1.0, value=0.5, step=0.1)
amp_b = st.sidebar.slider('Amplitude of Magnetic Field', min_value=0.0, max_value=1.0, value=0.5, step=0.1)
freq = st.sidebar.slider('Frequency of Waves', min_value=1, max_value=10, value=5, step=1)
# Calculate the electric and magnetic fields
e_x = amp_e * np.cos(freq*t)
e_y = np.zeros_like(e_x)
e_z = np.zeros_like(e_x)
b_x = np.zeros_like(e_x)
b_y = amp_b * np.cos(freq*t)
b_z = np.zeros_like(e_x)
# Plot the electric and magnetic fields
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111, projection='3d')
ax.quiver(x, y, np.zeros_like(x), e_x, e_y, e_z, length=0.1, color='r')
ax.quiver(x, y, np.zeros_like(x), b_x, b_y, b_z, length=0.1, color='b')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.view_init(elev=30, azim=120)
# Display the plot in Streamlit
st.pyplot(fig)