python - Matplotlib:如何增加热图中 bin 的大小(hexbin)?

标签 python matplotlib plot heatmap binning

Matplotlib:如何设置使用 hexbin 创建的 bin 的大小?我遇到的问题是垃圾箱太小,以至于图形看起来有点奇怪。

最佳答案

使用pylab_examples example code: hexbin_demo.py ,您可以轻松地使用所有可选参数来查看它们如何影响同一数据集。这是 gridsize 的作用:

enter image description here

<小时/>

我只是复制并粘贴演示中的代码(包括数据创建部分),然后为相同的参数制作具有不同值的子图,如下所示

plt.subplots_adjust(hspace=0.5)
plt.subplot(132)
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Gridsize 100 (default)")
cb = plt.colorbar()
cb.set_label('counts')

plt.subplot(133)
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r, gridsize = 200)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Gridsize 200")
cb = plt.colorbar()
cb.set_label('counts')

plt.subplot(131)
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r, gridsize = 10)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Gridsize 10")
cb = plt.colorbar()
cb.set_label('counts')

plt.show()
plt.close()

关于python - Matplotlib:如何增加热图中 bin 的大小(hexbin)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533445/

相关文章:

python - 暂停 matplotlib 自定义动画循环

python - 如何在 Python 3 中向 matplotlib 2.0 `ax` 对象添加黑色边框?

matlab - 一次绘制可变数量的向量?

python - 使用嵌套循环计算项目

python - 如何计算Pandas中分组数量的相关系数?

python - 表征我的 RAW 相机输出

python - 无法将 numpy 数组 reshape 为 RGB 图像

python - 当文件夹名称中有空格时使用 `os.path.exists` ?

python - 如何将seaborn regplot scattplot更改为lineplot?

matlab - 如何向图表添加适当的噪声