Reputation: 1
Can I put an outline around one element in a seaborn heatmap?
e.g., I want to put a yellow outline around the top-left element in this figure:
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()
Upvotes: 0
Views: 392
Reputation: 339320
Adding a rectangle is as easy as,
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()
For a more sophisticated solution, where the rectangle does not overlay the pixel it encompasses, see Set matplotlib rectangle edge to outside of specified width?.
Upvotes: 1