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