概述海上热图的一个要素

时间:2019-03-11 19:55:20

标签: python seaborn heatmap

我可以在海洋热图中围绕一个元素绘制轮廓吗?

例如,我想在此图的左上角元素周围添加黄色轮廓:

import matplotlib.pyplot as plt
import seaborn as sb

matrix = [[1, 2], [3, 4]]
index_of_element_to_outline = [0, 0]

sb.heatmap(matrix)
# insert some code to outline the given element 
plt.show()

1 个答案:

答案 0 :(得分:1)

添加矩形非常简单,

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

matrix = [[1, 2], [3, 4]]
index_of_element_to_outline = [0, 0]

ax = sns.heatmap(matrix)
rect = plt.Rectangle(index_of_element_to_outline, 1,1, color="gold", 
                     linewidth=3, fill=False, clip_on=False)
ax.add_patch(rect)

plt.show()

Django testing feature request

有关更复杂的解决方案,其中矩形不覆盖其包围的像素,请参见enter image description here