Heatmaps are often displayed with spatial coordinates on the horizontal and vertical axes. In addition to that, there are times when you want to take the horizontal axis as time, such as drawing the result of STFT (Short-Time Fourier Transform) where the horizontal axis is time and the vertical axis is frequency. At that time, I wanted to put a vertical line anywhere in the analysis to get a picture of when the event fired. I couldn't find a way to draw a vertical line with seaborn, so I'll leave it as a memorandum.
Put a vertical line in the heatmap
It seems that you can enter it normally using axvline. So I actually tried it.
vline_heatmap.py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
#Sample array creation
arr = np.random.rand(20, 20)
#Heat map display (left side)
fig, (ax1, ax2) = plt.subplots(1, 2)
sns.heatmap(arr, vmin=0, vmax=5, cmap="jet", ax=ax1)
#Display with vertical lines on the heat map (right side)
sns.heatmap(arr, vmin=0, vmax=5, cmap="jet", ax=ax2)
ax2.axvline(x=4, linewidth=2, color="w")
#drawing
plt.show()
The drawing result with no vertical line on the left and with vertical line on the right is shown.
Please write in the comments of this article or send to the following email address (change [at] to @).
akira.kashihara[at]hotmail.com
After investigating and tracing the vertical lines with reference to article 1, I came across article 2 and tried it. If you have any other articles that you are writing directly, please let me know.
Recommended Posts