可视化相似矩阵 S ∈ R n × n S\in\mathbb{R}^{n\times n} S∈Rn×n 用来画图,效果:
- 正方形格仔
- 去除纵、横轴 label
- 去除 color bar
- 去除白边

Code
import numpy as np
import seaborn as sns
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
S = np.array([[0.8, 2.4, 2.5, 3.9, 0.0, 4.0, 0.0],
[2.4, 0.0, 4.0, 1.0, 2.7, 0.0, 0.0],
[1.1, 2.4, 0.8, 4.3, 1.9, 4.4, 0.0],
[0.6, 0.0, 0.3, 0.0, 3.1, 0.0, 0.0],
[0.7, 1.7, 0.6, 2.6, 2.2, 6.2, 0.0],
[1.3, 1.2, 0.0, 0.0, 0.0, 3.2, 5.1],
[0.1, 2.0, 0.0, 1.4, 0.0, 1.9, 6.3]])
ax = sns.heatmap(S, cmap="YlGn",
square=True, # 正方形格仔
cbar=False, # 去除 color bar
xticklabels=False, yticklabels=False) # 去除纵、横轴 label
fig = ax.get_figure()
fig.savefig('class_sim_sub.jpg', bbox_inches='tight',
pad_inches=0.0) # 去白边
博客介绍了使用Python绘制可视化相似矩阵的热力图,包括呈现正方形格仔、去除纵横轴label、去除color bar等效果,还提及解决plt.savefig()保存图片白边问题,主要运用seaborn.heatmap和matplotlib。
1185

被折叠的 条评论
为什么被折叠?



