问题描述
我有两个数组,x
和 y
,它们的值都在一个明确定义的范围内.我可以创建一个六边形图(参见图片),但是,我现在想对这些分布进行归一化并在它们周围绘制等高线图.我对每个hexbin中的计数都不感兴趣.相反,我感兴趣的是显示对应于 1、2 和 3 个标准差 (σ) 的轮廓.我希望有一个输出显示类似于 this 示例的轮廓.分布为高斯分布.如果您对此有任何意见,我将不胜感激.
I have two arrays, x
and y
, both with values within a well defined range. I am able to create a hexbin plot (see image), however, I would now like to normalize these distributions and draw contour plots around them. I am not so interested in the counts within each hexbin. Instead I am interested in showing the contours corresponding to 1, 2 and 3 standard deviations (σ). I hope to have an output showing the contours similar to this example. The distribution is Gaussian. I would greatly appreciate any input on this.
推荐答案
根据 hexbin 文档 https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hexbin.html ,您应该可以访问箱和返回变量的值.例如:
According to the hexbin documentation https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hexbin.html you should be able to access the (x,y) locations of the bins and the values from the returned variable. For example:
h = hexbin(...)
xy = h.get_offsets()
v = h.get_array()
您可以使用这些来绘制轮廓.
You can use these to draw your contour.
请注意,文档不正确,并说应该调用 get_offset()
,但该函数不存在,它是 get_offsets()
.
Note that the documentation is incorrect and says get_offset()
should be called, but that function does not exist, it is get_offsets()
.
此外,当使用 xscale='log'
和 yscale='log'
调用 hexbin
时,则 get_offsets()
仅返回 array([[0.,0.]])
.
In addition, when hexbin
is called with xscale='log'
and yscale='log'
, then get_offsets()
only returns array([[0., 0.]])
.
这篇关于如何在 hexbin 图的顶部绘制轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!