python - 如何在 pyplot 图中突出显示某个值?
问题描述
我创建了三个高斯的简单 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')
解决方案
推荐阅读
- python - 基于 CharField 选择动态生成 Django 表单
- python - 具有 groupby 两个特征的箱线图
- java - 在选项卡布局/片段中切换时 Android 应用程序崩溃
- docker - 将 cron 添加到 Docker 映像
- python - numpy.where - 奇怪的行为:新元素不知从何而来?
- reactjs - 使用 WebStorm,如何让 React 自动导入组件在 HOC 上工作
- python - 蟒蛇 | 从未知目的地复制文件
- python - python多处理池阻塞主线程
- javascript - 如果路径中存在文件,我想在输入类型中设置自动选择的文件
- android - Firebase 存储在上传到数据库期间出错