六邊形分箱繪圖#

hexbin 是一個 2D 直方圖繪圖,其中箱子是六邊形,顏色表示每個箱子內資料點的數量。

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

n = 100_000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xlim = x.min(), x.max()
ylim = y.min(), y.max()

fig, (ax0, ax1) = plt.subplots(ncols=2, sharey=True, figsize=(9, 4))

hb = ax0.hexbin(x, y, gridsize=50, cmap='inferno')
ax0.set(xlim=xlim, ylim=ylim)
ax0.set_title("Hexagon binning")
cb = fig.colorbar(hb, ax=ax0, label='counts')

hb = ax1.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
ax1.set(xlim=xlim, ylim=ylim)
ax1.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax1, label='counts')

plt.show()
Hexagon binning, With a log color scale

標籤: 繪圖類型:直方圖 繪圖類型:六邊形分箱圖 領域:統計

參考文獻

此範例中顯示了以下函數、方法、類別和模組的使用

腳本總執行時間: (0 分鐘 2.298 秒)

由 Sphinx-Gallery 產生的圖庫