我可以在海洋热图中围绕一个元素绘制轮廓吗?
例如,我想在此图的左上角元素周围添加黄色轮廓:
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()
答案 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()