Python Scipy normal pdf评估给出了矛盾的值

Python Scipy normal pdf评估给出了矛盾的值,python,matplotlib,plot,scipy,statistics,Python,Matplotlib,Plot,Scipy,Statistics,我试图写下一个图,表明无偏估计量并不总是最好的估计量。以下是我为获得一张好看的图片而编写的代码: # Set up the plot fig, ax = plt.subplots() # Create some data y = np.linspace(-10, 10, 1000) # Plot two normals, one centered around 0 but with large variance ax.plot(y, norm.pdf(y, scale=3), 'k-', lab

我试图写下一个图,表明无偏估计量并不总是最好的估计量。以下是我为获得一张好看的图片而编写的代码:

# Set up the plot
fig, ax = plt.subplots()
# Create some data
y = np.linspace(-10, 10, 1000)
# Plot two normals, one centered around 0 but with large variance
ax.plot(y, norm.pdf(y, scale=3), 'k-', label=r"pdf of $\hat{\theta_1}$")
# One centered around 1 with small variance
ax.plot(y, norm.pdf(y, loc=1, scale=1), 'r--', label=r"pdf of $\hat{\theta_2}$")
ax.legend()
# Remove left, right and top axis, remove y axis labels and ticks
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.tick_params(axis='y', which='both', left=False, right=False, labelleft=False)
# Remove x axis ticks and labels, keep only one at x=0
ax.set_xticks([0])
ax.set_xticklabels([r"$\theta$"])
# Plot vertical line at x=0 from y=0 to the value of the first pdf
ax.axvline(x=0, ymin=0, ymax=norm.pdf(0, scale=3), linestyle=":")
# Plot second vertical line for second normal distribution
ax.axvline(x=1, ymin=0, ymax=norm.pdf(1, loc=1, scale=1), linestyle=":")
# Remove margins so that pdfs lie on the axis
ax.margins(0)
plt.show(block=True)
基本上,我想画两个正态分布,一个以0为中心,但方差很大,另一个以1为中心,方差很小。然后我想添加两条垂直线。一条线穿过x=0,在x=0时达到第一个正态分布的值,第二条线穿过x=1,在x=1时达到第二个正态分布的值。然而,这些线要小得多,我不知道为什么

我唯一的猜测是,由于这些是连续的pdf,如果我在某一点上对它们进行评估,scipy会做一些奇怪的事情

导入

我忘了提到我的进口,我把它们包括在这里,这样你就可以有一个MWE

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm
查看以下文件:

线是在数据坐标中定义的,而不是在轴坐标中定义的。你需要改用


我真是太傻了!非常感谢@不要对自己太苛刻,我们都有过;)我实际上是想用求积来估计积分的值。。。但解决办法是这样的simpler@Euler_Salter是 啊您可以检查输入绘图调用的y值,它们是相同的。即使他们错了,他们也应该犯同样的错误。值应该是
1/sqrt(4*pi*sigma**2)
;)
ymax : scalar, optional, default: 1
 Should be between 0 and 1, 0 being the bottom of the plot, 1 the top of the plot.
# Plot vertical line at x=0 from y=0 to the value of the first pdf
ax.vlines(x=0, ymin=0, ymax=norm.pdf(0, scale=3), linestyle=":")
# Plot second vertical line for second normal distribution
ax.vlines(x=1, ymin=0, ymax=norm.pdf(1, loc=1, scale=1), linestyle=":")