我想创建一个热力图,并为特定的行使用不同的。例如,我希望基准行使用,而其他行使用。到目前为止,我有以下代码。我无法弄清如何实现这一点。
谢谢。
谢谢。
import numpy as np
import matplotlib.pyplot as plt
y_ticks = ["f", "e", "d", "c",
"b", "a", "baseline"]
x_ticks = ["A", "B", "C",
"D", "E", "F", "G"]
data = 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]])
data_1 = np.delete(data, (1,2,3,4,5,6), axis=0)
data_2 = np.delete(data, (0), axis=0)
fig, ax = plt.subplots()
im_1 = ax.imshow(data_1, cmap='Blues')
im_2 = ax.imshow(data_2, cmap='Reds')
im = np.vstack((im_1, im_2))
ax.set_xticks(np.arange(len(x_ticks)))
ax.set_yticks(np.arange(len(y_ticks)))
ax.set_xticklabels(x_ticks)
ax.set_yticklabels(y_ticks)
plt.setp(ax.get_xticklabels(), ha="right", rotation_mode="anchor")
# Loop over data dimensions and create text annotations.
for i in range(len(y_ticks)):
for j in range(len(x_ticks)):
text = ax.text(j, i, data[i, j], ha="center", va="center")
fig.tight_layout()
plt.show()