失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python画概率密度图_绘制概率密度

python画概率密度图_绘制概率密度

时间:2018-12-24 09:59:01

相关推荐

python画概率密度图_绘制概率密度

最常见的方法是使用fill_between对置信区间之间的区域进行着色。例如:import numpy as np

np.random.seed(1977)

import matplotlib.pyplot as plt

# Generate data...

x_obs = np.linspace(-2, 2, 20)

true_model = [0.2, -0.1, 4, 2, 1, 0]

noise = np.random.normal(0, 5, x_obs.shape)

y_obs = np.polyval(true_model, x_obs) + noise

# Fit to a 5-th order polynomial

fit_model = np.polyfit(x_obs, y_obs, 5)

x = np.linspace(-3, 3, 100)

y_true = np.polyval(true_model, x)

y_pred = np.polyval(fit_model, x)

# Made up confidence intervals (Im too lazy to do the math...)

high_bound = y_pred + 3 * (0.5 * x**4 + 3)

low_bound = y_pred - 3 * (0.5 * x**4 + 3)

# Plot the results...

fig, ax = plt.subplots()

ax.fill_between(x, high_bound, low_bound, color=gray, alpha=0.5)

ax.plo

如果觉得《python画概率密度图_绘制概率密度》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。