怎样绘制三角形作为bin的热图。比如matplotlib的hexbin可以绘制六边形的bin
生成了一个10x10的随机数据矩阵。然后使用hexbin函数将该矩阵的每个元素分为6个等宽的bin,并使用cmap参数指定了颜色映射
import matplotlib.pyplot as plt
import numpy as np
# 生成随机数据
data = np.random.rand(10, 10)
# 绘制hexbin图
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(8, 8))
hexbins = ax[0].hexbin(data[:, 0], data[:, 1], bins=6, cmap=plt.cm.get_cmap('jet', 10))
# 添加标签和标题
ax[0].set_xlabel('x')
ax[0].set_ylabel('y')
ax[0].set_title('Hexagonal binning of data')
ax[1].set_xlabel('x')
ax[1].set_ylabel('y')
ax[1].set_title('Hexagonal binning of data')
# 显示图形
plt.show()