1
我使用子圖形生成4個熱圖,並且要求y軸反轉。我正在使用ax[i].invert_yaxis()
,但它似乎沒有工作。的代碼的一個例子是下面:在Python中不反轉的熱圖的y軸
everything = [data_y_axis, data_length, data_roundness, data_y_SDev]
legend = ['title1', 'title2', 'title3', 'title4']
fig, ax = plt.subplots(nrows = 1, ncols = 4, sharex = False, sharey = True, figsize = (13,3))
ax = ax.flatten()
for i, v in enumerate(everything):
heatmap = ax[i].pcolor(v, cmap=plt.cm.Blues)
ax[i].invert_yaxis()
ax[i].xaxis.tick_top()
ax[i].set_xticks(np.arange(v.shape[1])+0.5, minor=False)
ax[i].set_xticklabels(column_labels, minor=False)
ax[i].set_yticks(np.arange(v.shape[0])+0.5, minor=False)
ax[i].set_yticklabels(row_labels, minor=False, fontproperties = titlefont)
ax[i].set_xticklabels(column_labels, minor=False, fontproperties = titlefont)
cb = fig.colorbar(heatmap, orientation='horizontal', pad=0.02, ax = ax[i])
cb.set_label(label = legend[i], fontproperties = titlefont)
cb.outline.set_linewidth(2)
在everything
的項目只是np.arrays,它們都具有相同的形狀(4,6)。
我做了什麼明顯錯誤?
試着將'invert_yaxis'移動到set-ticks-axis-stuff-thing的底部。也許'set_yticks'或其他命令正在使你的反轉向上? – pathoren
剛剛去了你的建議,它仍然沒有工作,我很害怕! –
爲了清楚起見:你想翻轉數據而不是yaxis?也許我首先誤解了你 – pathoren