Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyplot:在散点图中包含一定数量点(或一定概率值)的等高线?_Python_Matplotlib_Contour_Kernel Density - Fatal编程技术网

Python Pyplot:在散点图中包含一定数量点(或一定概率值)的等高线?

Python Pyplot:在散点图中包含一定数量点(或一定概率值)的等高线?,python,matplotlib,contour,kernel-density,Python,Matplotlib,Contour,Kernel Density,我想从散点图创建PDF。这是我当前使用的代码: data = np.column_stack((x, y)) nbins = 100 xmin = -0.5; xmax = 0.5; ymin = -5; ymax = 5 k = kde.gaussian_kde(data.T) xi, yi = np.mgrid[xmin:xmax:nbins*1j, ymin:ymax:nbins*1j] zi = k(np.vstack([xi.flatten(), yi.flatten()])) fig

我想从散点图创建PDF。这是我当前使用的代码:

data = np.column_stack((x, y))
nbins = 100
xmin = -0.5; xmax = 0.5; ymin = -5; ymax = 5
k = kde.gaussian_kde(data.T)
xi, yi = np.mgrid[xmin:xmax:nbins*1j, ymin:ymax:nbins*1j]
zi = k(np.vstack([xi.flatten(), yi.flatten()]))
fig, ax = plt.subplots(figsize=(5.5,4))
plt.pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap='Purples')
plt.contour(xi, yi, zi.reshape(xi.shape), levels = [0.2, 0.5, 0.7, 1, 1.5], linewidths=1, linestyles='dashed', cmap='viridis')
plt.xlabel('$x$')
plt.ylabel('$y$]')
plt.grid(True, linestyle='--')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
fig.savefig('test.png', dpi=600)
plt.close(fig)
这是我从代码中得到的情节:

关于这一点,我有两个问题:

  • PDF似乎有问题,因为我可以在1级和1.5级绘制等高线,而且它是PDF,所以值应该小于1
  • 如何绘制包含一定数量点或以一定概率水平的等高线

数据:和。(格式:)

PDF不受1的限制。唯一的要求是积分等于1。第二个问题可能很难,它涉及到动态计算积分,以交互地达到包含所需概率的所需水平。谢谢@ImportanceOfBeingErnest!那么等高线的水平是什么意思呢?例如,等高线为1.5意味着什么?在这种情况下,等高线为1.5表示概率密度为1.5的区域。因此,它包围了概率密度高于1.5的区域。