Untitled
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation # Generate time (hours) and corresponding prolactin levels hours = np.linspace(0, 24, 1000) prolactin_levels = 10 + 5 * np.sin((2 * np.pi / 24) * hours - np.pi / 2) # Simulating a circadian rhythm # Initialize the figure fig, ax = plt.subplots(figsize=(8, 5)) ax.set_xlim(0, 24) ax.set_ylim(0, 20) ax.set_xlabel("Time (hours)") ax.set_ylabel("Prolactin Levels (arbitrary units)") ax.set_title("Prolactin Production Over 24 Hours") line, = ax.plot([], [], color="blue", lw=2, label="Prolactin Level") ax.legend() # Initialize the graph def init(): line.set_data([], []) return line, # Update function for animation def update(frame): line.set_data(hours[:frame], prolactin_levels[:frame]) return line, # Create the animation ani = FuncAnimation(fig, update, frames=len(hours), init_func=init, blit=True, interval=10) # Save the animation ani.save('Prolactin_Production_Animation.mp4', fps=30, extra_args=['-vcodec', 'libx264']) print("Animation saved as 'Prolactin_Production_Animation.mp4'")
Leave a Comment