我有一个与这个问题密切相关的问题:
Normed histogram y-axis larger than 1个
上述螺纹的解决方案是适当调整轴的尺寸. 然而,该解决方案不适用于我的代码:
import numpy as np
import matplotlib.pyplot as plt
from numpy import random
import seaborn as sns
np.random.seed(2023)
a = np.random.normal(0, 1, 100000)
sns.histplot(a, bins=np.arange(-5, 5, 0.01), stat='density', color = 'red')
plt.title("Standard Normal Distribution")
plt.xlabel('x')
plt.ylabel('F(x)', rotation=0)
plt.show()
上述代码的图形如下所示:
上图是x轴上从-5到+5的标准正态分布,阶跃宽度为0.01,就像代码中由np.arange()
定义的那样.
现在我想修改我的代码,以便得到完全相同的绘图,所有内容都在相同的位置,就像上面一样,但x轴从-500到500,而不是-5到5,步长为1而不是0.01.
The above solution (Normed histogram y-axis larger than 1个) suggests modifying the value a
, so that if the dimension in the x-axis gets multiplied by a factor of 100, I'd need to divide the y-axis by a factor of 100. However, modifying my code like this
import numpy as np
import matplotlib.pyplot as plt
from numpy import random
import seaborn as sns
np.random.seed(2023)
a = np.random.normal(0, 1, 100000)
b = a/ 100
sns.histplot(b, bins=np.arange(-500, 500, 1), stat='density', color = 'red')
plt.title("Standard Normal Distribution")
plt.xlabel('x')
plt.ylabel('F(x)', rotation=0)
plt.show()
结果如下所示:
首先很有趣,因为它提出了另一个问题:当这样的函数只有一个可能的概率区域时,它能被认为是正态分布函数吗?所以它就像一个总面积为1的正方形?
回到原来的问题:我如何修改我的代码,使绘图在x轴上显示-500到500之间的x值,步长为1,并且中心(x=0)的y值大约为0.004?