normal distribution - chunhualiao/public-docs GitHub Wiki

sigma an percentile

https://python-fiddle.com/examples/matplotlib?checkpoint=1752123603

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as st

# Generate a range of sigma (z-score) values from -3 to 3
sigma_values = np.linspace(-3, 3, 100)

# Calculate the corresponding percentiles using the CDF of a normal distribution
# The result is multiplied by 100 to convert from a proportion to a percentile
percentiles = st.norm.cdf(sigma_values) * 100

# Create the plot and set its size
plt.figure(figsize=(10, 6))

# Plot the main S-curve
plt.plot(sigma_values, percentiles, label='S-Curve')

# Add a grid for better readability
plt.grid(True)

# Set the title and axis labels
plt.title('Relationship between σ Values and Percentiles (Normal Distribution)')
plt.xlabel('σ (Standard Deviations from the Mean)')
plt.ylabel('Percentile')

# Define some typical sigma values to highlight on the plot
typical_sigmas = [-2, -1, 0, 1, 2]
typical_percentiles = st.norm.cdf(typical_sigmas) * 100

# Loop through the typical values to add annotations
for sigma, percentile in zip(typical_sigmas, typical_percentiles):
    # Add a red dot for each typical value
    plt.plot(sigma, percentile, 'ro')
    # Add the text label with an arrow
    plt.annotate(f'({sigma}σ, {percentile:.1f}th)',
                 xy=(sigma, percentile),
                 xytext=(sigma + 0.2, percentile - 5),
                 arrowprops=dict(facecolor='black', shrink=0.05, width=1, headwidth=5),
                 fontsize=9)

# Add dashed lines to mark the 50th percentile and 0σ mean
plt.axvline(0, color='grey', linestyle='--')
plt.axhline(50, color='grey', linestyle='--')

# Display the plot
plt.show()

image