散景的 histogram2d 示例

histogram2d example for bokeh

令人惊讶的是,没有人愿意在 2D 直方图绘制的散景画廊中制作示例

numpy

histogram2d 给出了原始的 material,但是最好有一个例子,因为 matplotlib

有什么简单的制作方法吗?

根据建议的答案,让我附上一个案例,其中 hexbin 不适合这项工作,因为 exagons 不适合这项工作。另请查看 matplotlib 结果。

当然我不是说散景不能做到这一点,但它似乎并不直接。足以将 hexbin 图更改为方形 bin 图,但 quad(left, right, top, bottom, **kwargs) 似乎没有这样做,hexbin 也没有选择更改 "tile" 形状的选项。

你可以用相对较少的代码行做一些接近的事情(与this example from the matplotib gallery). Note bokeh has some examples for hex binning in the gallery here and here. Adapting those and the example provided in the numpy docs比较你可以得到以下内容:

import numpy as np

from bokeh.plotting import figure, show
from bokeh.layouts import row

# normal distribution center at x=0 and y=5
x = np.random.randn(100000)
y = np.random.randn(100000) + 5

H, xe, ye = np.histogram2d(x, y, bins=100)

# produce an image of the 2d histogram
p = figure(x_range=(min(xe), max(xe)), y_range=(min(ye), max(ye)), title='Image')

p.image(image=[H], x=xe[0], y=ye[0], dw=xe[-1] - xe[0], dh=ye[-1] - ye[0], palette="Spectral11")

# produce hexbin plot
p2 = figure(title="Hexbin", match_aspect=True)
p.grid.visible = False

r, bins = p2.hexbin(x, y, size=0.1, hover_color="pink", hover_alpha=0.8, palette='Spectral11')

show(row(p, p2))