fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. # สร้างช่วงของค่า t สำหรับกราฟ
  5. t_values = np.linspace(-10, 10, 400)
  6. t_dist = stats.t.pdf(t_values, df) # คำนวณความหนาแน่นของ t-distribution
  7.  
  8. # สร้างกราฟ
  9. plt.figure(figsize=(8, 5))
  10. plt.plot(t_values, t_dist, label="t-Distribution", color="blue")
  11.  
  12. # แรเงาพื้นที่ของค่าขีดวิกฤติ (Critical Regions)
  13. plt.fill_between(t_values, t_dist, where=(t_values >= t_critical), color='red', alpha=0.3, label="Rejection Region")
  14. plt.fill_between(t_values, t_dist, where=(t_values <= -t_critical), color='red', alpha=0.3)
  15.  
  16. # เส้นค่าทดสอบ t
  17. plt.axvline(t_stat, color="black", linestyle="dashed", label=f"t = {t_stat:.2f}")
  18.  
  19. # เส้นค่าขีดวิกฤติ
  20. plt.axvline(t_critical, color="red", linestyle="dashed", label=f"Critical t = {t_critical:.2f}")
  21. plt.axvline(-t_critical, color="red", linestyle="dashed")
  22.  
  23. # กำหนดชื่อแกนและชื่อกราฟ
  24. plt.xlabel("t-value")
  25. plt.ylabel("Density")
  26. plt.title("T-Distribution with Critical Regions")
  27.  
  28. # แสดงคำอธิบายกราฟ
  29. plt.legend()
  30. plt.grid()
  31.  
  32. # แสดงกราฟ
  33. plt.show()
  34.  
Success #stdin #stdout 0.04s 25876KB
stdin
Standard input is empty
stdout
import numpy as np
import matplotlib.pyplot as plt

# สร้างช่วงของค่า t สำหรับกราฟ
t_values = np.linspace(-10, 10, 400)
t_dist = stats.t.pdf(t_values, df)  # คำนวณความหนาแน่นของ t-distribution

# สร้างกราฟ
plt.figure(figsize=(8, 5))
plt.plot(t_values, t_dist, label="t-Distribution", color="blue")

# แรเงาพื้นที่ของค่าขีดวิกฤติ (Critical Regions)
plt.fill_between(t_values, t_dist, where=(t_values >= t_critical), color='red', alpha=0.3, label="Rejection Region")
plt.fill_between(t_values, t_dist, where=(t_values <= -t_critical), color='red', alpha=0.3)

# เส้นค่าทดสอบ t
plt.axvline(t_stat, color="black", linestyle="dashed", label=f"t = {t_stat:.2f}")

# เส้นค่าขีดวิกฤติ
plt.axvline(t_critical, color="red", linestyle="dashed", label=f"Critical t = {t_critical:.2f}")
plt.axvline(-t_critical, color="red", linestyle="dashed")

# กำหนดชื่อแกนและชื่อกราฟ
plt.xlabel("t-value")
plt.ylabel("Density")
plt.title("T-Distribution with Critical Regions")

# แสดงคำอธิบายกราฟ
plt.legend()
plt.grid()

# แสดงกราฟ
plt.show()