import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from scipy.stats import norm

# Set up the figure and axis for plotting
fig, ax = plt.subplots(figsize=(8, 6))

# Set up the initial plot
line_cdf, = ax.plot([], [], label='CDF', color='blue')

# Labels and title
ax.legend()
ax.grid(True)

# Set axis limits (adjust these based on the standard deviation range you want to see)
ax.set_xlim(-10, 10)
ax.set_ylim(0, 1)

# Animation function to update the plot
def animate(std_dev):
    """Update the plot for each frame with varying standard deviation."""
    # Generate x values for plotting the CDF
    x_values = np.linspace(-10, 10, 1000)
    
    # Calculate the CDF for the current standard deviation
    cdf_values = norm.cdf(x_values, loc=0, scale=std_dev)
    
    # Update CDF line (x-values for the CDF)
    line_cdf.set_data(x_values, cdf_values)
    
    return line_cdf,

# List of standard deviations for animation
std_devs = np.linspace(0.5, 5, 100)

# Create animation with a longer interval for smoother transitions
ani = FuncAnimation(fig, animate, frames=std_devs, interval=100, blit=True)

if True:
    ani.save('cumulative-quantile-gaussian.mp4', writer='ffmpeg', fps=10)

# Show the animation
plt.show()
