You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让matplotlib.hexbin绘制的六边形实现平边向上的显示效果

hexbin平边朝上显示实现方法

可以实现,matplotlib.pyplot.hexbin内置了朝向控制参数,无需额外做坐标变换:

  • 默认orientation='vertical':对应尖边沿y轴朝上的默认效果
  • 设置orientation='horizontal':即可实现平边朝上的90度旋转效果

修改后的完整代码如下:

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(1000)*2-1
y = np.random.rand(1000)*2-1

plt.hexbin(x, y, gridsize=10, orientation='horizontal')
plt.show()

如果遇到低版本matplotlib不支持orientation参数的场景,可以用交换x、y输入值的替代方案,同步调整轴标签即可:

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(1000)*2-1
y = np.random.rand(1000)*2-1

# 交换x、y输入实现旋转效果
plt.hexbin(y, x, gridsize=10)
# 按需修正轴标签
plt.xlabel('原x轴对应数值')
plt.ylabel('原y轴对应数值')
plt.show()

内容的提问来源于stack exchange,提问作者Thomas Wagenaar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 07:24:03