import matplotlib.pyplot as plt
import numpy as np
plt.figure()
heatmap = plt.pcolor(df, cmap='viridis')
# Add text
for y in range(df.shape[0]):
for x in range(df.shape[1]):
plt.text(x + 0.5, y + 0.5, '{:.0f}'.format(df.iloc[y, x]),
color='w',horizontalalignment='center',
verticalalignment='center',)
plt.yticks(np.arange(0.5, len(df.index), 1), df.index)
plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns)
plt.colorbar(heatmap)
plt.ylabel('points')
plt.xlabel('price')
可以使用Matplotlib生成热图并对其进行注释:
您还可以使用seaborn更轻松地获取带注释的热图:
^{pr2}$Seaborn在自动格式化文本底纹方面做得很好,这样它在不断变化的背景颜色下是可见的。在
相关问题 更多 >
编程相关推荐