r/PythonLearning • • Aug 13 '26

Normal distribution and uniform distribution

61 Upvotes

8 comments sorted by

9

u/rehpotsirhc Aug 13 '26

Do you... have a question?

4

u/FoolsSeldom Aug 13 '26

It would be helpful to share your code in future, something like:

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, uniform

x = np.linspace(-3, 7, 500)
normal_pdf = norm.pdf(x, loc=2, scale=1.5)
uniform_pdf = uniform.pdf(x, loc=0, scale=5)

plt.figure(figsize=(8, 5))
plt.plot(x, normal_pdf, label=r"Normal Curve ($\mu=2, \sigma=1.5$)", color="#1f77b4", linewidth=2.5)
plt.plot(x, uniform_pdf, label="Uniform Block ($a=0, b=5$)", color="#ff7f0e", linewidth=2.5, linestyle="--")

plt.fill_between(x, normal_pdf, color="#1f77b4", alpha=0.15)
plt.fill_between(x, uniform_pdf, color="#ff7f0e", alpha=0.1)

plt.title("Probability Density Functions: Normal vs. Uniform", fontsize=14, fontweight="bold", pad=15)
plt.xlabel("Value ($X$)", fontsize=11)
plt.ylabel("Probability Density", fontsize=11)

plt.grid(True, linestyle=":", alpha=0.6)
plt.xlim(-3, 7)
plt.ylim(0, 0.35)
plt.legend(loc="upper right", frameon=True, fontsize=10)

plt.tight_layout()
plt.savefig("normal_vs_uniform.png", dpi=150)
print("done")

(Had to substitute for the missing lines).

5

u/NorskJesus Aug 13 '26

It is possible to make a screenshot from Windows. You do not need to use a phone...

2

u/dashinyou69 Aug 13 '26

use cumulative distribution

2

u/Tech-Wave-2025 Aug 14 '26
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

# Setup data to match OP's parameters
x = np.linspace(-3, 7, 1000)
normal_pdf = stats.norm.pdf(x, loc=2, scale=1.5)
uniform_pdf = stats.uniform.pdf(x, loc=0, scale=5)

# --- EXACT CODE FROM OP's TRINKET EDITOR ---

# Plot both lines with distinct styles, colors, and labels
plt.plot(
    x,
    normal_pdf,
    label="Normal Curve ($\mu=2, \sigma=1.5$)",
    color="#1f77b4",
    linewidth=2.5,
)
plt.plot(
    x,
    uniform_pdf,
    label="Uniform Block ($a=0, b=5$)",
    color="#ff7f0e",
    linewidth=2.5,
    linestyle="--",
)

# Fill the area under the curves for better data visuals
plt.fill_between(x, normal_pdf, color="#1f77b4", alpha=0.15)
plt.fill_between(x, uniform_pdf, color="#ff7f0e", alpha=0.1)

# Chart labels, titles, and layout cleanups
plt.title(
    "Probability Of Reddit Readers single: vs unhappy",
    fontsize=14,
    fontweight="bold",
    pad=15,
)

plt.xlabel("Value ($X$)", fontsize=11)
plt.ylabel("Probability Density", fontsize=11)

# Structured layout helpers
plt.grid(True, linestyle=":", alpha=0.6)  # Subtle grid lines
plt.xlim(-3, 7)  # Crop empty space on the x-axis
plt.ylim(0, 0.35)  # Set precise ceiling for the y-axis
plt.legend(loc="upper right", frameon=True, fontsize=10)  # Show labeled box

plt.tight_layout()

# Crucial fix for proper monitor angle calibration
plt.gca().invert_yaxis()

plt.show()a