如何在热图的每个块之间添加间距
我有这样的矩阵。有什么方法可以在不更改缩放的情况下之间添加一些白线。我已经使用matplotlib作为此图:
代码 - >
# final heatmap code with correct color range
import matplotlib.pyplot as plt
import numpy as np
def heatmap2d(arr: np.ndarray):
plt.imshow(arr, cmap='jet', interpolation = "none",vmin = 140, vmax = 395)
plt.colorbar()
plt.show()
test_array = [
[220, 152, 146, 151, 146, 144],
[142, 156, 290, 174, 152, 151],
[148, 190, 390, 370, 146, 152],
[143, 142, 380, 375, 146, 152],
[154, 146, 154, 172, 150, 152],
[150, 152, 144, 140, 142, 0]
]
heatmap2d(test_array)
I have a matrix like this. Is there a way I can add some white lines between it without changing the scaling. I have used matplotlib for this graph:
Something like this should work.:
Code ->
# final heatmap code with correct color range
import matplotlib.pyplot as plt
import numpy as np
def heatmap2d(arr: np.ndarray):
plt.imshow(arr, cmap='jet', interpolation = "none",vmin = 140, vmax = 395)
plt.colorbar()
plt.show()
test_array = [
[220, 152, 146, 151, 146, 144],
[142, 156, 290, 174, 152, 151],
[148, 190, 390, 370, 146, 152],
[143, 142, 380, 375, 146, 152],
[154, 146, 154, 172, 150, 152],
[150, 152, 144, 140, 142, 0]
]
heatmap2d(test_array)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Seaborn使这很容易。调用
sns.heatmap
,然后传递lineWidths
参数。Seaborn makes this pretty easy. Call
sns.heatmap
, and pass thelinewidths
parameter.遵循,您可以在轴上添加额外的小滴答,并在这些小滴答上涂上白色网格。它会对您的热图产生填充效果,例如图
Following the tutorial of matplotlib, you can add extra minor ticks on the axes and apply a white grid on those minor ticks. It causes a padding effect on your heatmap like plot