要使用matplotlib的plt.imshow更改热图的y刻度标签,可以按照以下步骤进行操作:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(10, 10) # 创建一个10x10的随机数据矩阵
plt.imshow(data, cmap='hot') # 绘制热图
plt.colorbar() # 添加颜色条
y_labels = ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6', 'Label 7', 'Label 8', 'Label 9', 'Label 10']
plt.yticks(np.arange(len(y_labels)), y_labels) # 设置y刻度标签
完整的代码示例:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(10, 10)
plt.imshow(data, cmap='hot')
plt.colorbar()
y_labels = ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6', 'Label 7', 'Label 8', 'Label 9', 'Label 10']
plt.yticks(np.arange(len(y_labels)), y_labels)
plt.show()
这样就可以使用plt.imshow更改热图的y刻度标签了。
领取专属 10元无门槛券
手把手带您无忧上云