matplotlib でヒートマップをプロットし、これを基礎として使用しようとしています:
問題は、3 列しかないのに 70 行しかないのに、この例を使用すると、図は常に 70 行と 70 列になることです。列の量を制限する方法を知っている人はいますか?それらは私のデータに適合しますか?
matplotlib でヒートマップをプロットし、これを基礎として使用しようとしています:
問題は、3 列しかないのに 70 行しかないのに、この例を使用すると、図は常に 70 行と 70 列になることです。列の量を制限する方法を知っている人はいますか?それらは私のデータに適合しますか?
私のコードにバグが見つかりました。インデックス ( のdata.shape
) を逆にしました。
import matplotlib.pyplot as plt
import numpy as np
column_labels = list('ABC')
row_labels = range(7)
data = np.random.rand(7,3)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[1])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0])+0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
ax.set_xticklabels(column_labels, minor=False)
ax.set_yticklabels(row_labels, minor=False)
plt.show()
収量