Matplotlib:hexbin 图中六边形之间的空间?

时间:2020-12-27 16:35:58

标签: python matplotlib

我正在使用以下 Python 脚本制作 hexbin 图:

## object of Pitch class
pitch = Pitch(
    line_color="#747474", pitch_color="#222222", orientation="vertical", half=True, plot_arrow=False
)

## plot the pitch
fig, ax = pitch.create_pitch()

## color-map
cmap = [
    "#222222", "#2A2224", "#3A2027", "#421F28", 
    "#54202B", "#65202E", "#782231", "#892433", "#9B2838",
    "#AC2B3A", "#BE2F3E", "#CF3341", "#E13746"
]
cmap = colors.ListedColormap(cmap)

## make hexbins
hexbin = ax.hexbin(
    68 - shots_data['Y'], shots_data['X'], zorder=3, cmap=cmap,
    extent=(0, 68, 52, 104), gridsize=25, bins=13
)

它正在生成以下输出:

enter image description here

现在我想在每个六边形之间留出小空间,但我不知道在脚本中添加什么来实现它。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

你可以设置一个白色的边缘颜色,和一些细线宽度:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors

np.random.seed(0)
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)

fig, ax = plt.subplots(figsize=(7, 4))

cmap = colors.ListedColormap(["#222222", "#2A2224", "#3A2027", "#421F28", "#54202B", "#65202E", "#782231",
                              "#892433", "#9B2838", "#AC2B3A", "#BE2F3E", "#CF3341", "#E13746"])
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap=cmap, ec='white', lw=0.5)
ax.margins(x=-0.1, y=-0.1)

plt.show()

example plot

相关问题