我创建了一个由三个高斯组成的简单pyplot。现在,我想从x轴到每个高斯的峰值绘制一条虚线。这可能吗?
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
import math
mu1 = 5
mu2 = 10
variance1 = 3
variance2 = 1
sigma1 = math.sqrt(variance1)
sigma2 = math.sqrt(variance2)
mu_combined = (variance2*mu1 + variance1*mu2)/(variance1 + variance2)
variance_combined = 1/(1/variance1 + 1/variance2)
sigma_combined = math.sqrt(variance_combined)
x = np.linspace(0,15,100)
plt.plot(x,norm.pdf(x, mu1, sigma1),'b')
plt.plot(x,norm.pdf(x, mu2, sigma2),'r')
plt.plot(x,norm.pdf(x, mu_combined, sigma_combined),'g')
plt.plot([5,5],[0,0.23],'b:')
plt.plot([10,10],[0,0.4],'r:')
plt.plot([8.7,8.7],[0,0.46],'g:')
ax = plt.gca()
ax.set_xlabel('Random Variable')
ax.set_ylabel('Probability')
plt.grid()
plt.show()
plt.savefig('Program_Path/Gaussians.svg', format='svg')