2016-08-03 16 views
1

Ich erzeuge 4 Heatmaps mit Subplots und möchte die y-Achse invertiert. Ich benutze ax[i].invert_yaxis(), aber es scheint nicht zu funktionieren. Ein Beispiel für den Code ist unten:y-Achse der Heat Map in Python nicht invertieren

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) 

Die Elemente in everything np.arrays sind gerade, von denen alle die gleiche Form (4, 6).

Es produziert derzeit Karten wie folgt: enter image description here und sollte so aussehen: enter image description here.

Habe ich etwas offensichtlich falsch gemacht?

+0

Versuchen Sie Ihre 'invert_yaxis' auf den Grund des Set-Ticks-Achsen-Zeug-Ding zu verschieben. Vielleicht 'set_yticks' oder die anderen Befehle schrauben deine Inversion hoch? – pathoren

+0

Ich hatte nur einen Versuch, was Sie vorgeschlagen haben und es hat immer noch nicht funktioniert Ich habe Angst! –

+0

Aus Gründen der Übersichtlichkeit: Sie möchten die DATA nicht die YAXIS drehen? Vielleicht habe ich dich zuerst falsch verstanden – pathoren

Antwort

0

Aha. Ich habe es gelöst. Ich entfernte ax[i].invert_yaxis() aus der for Schleife und steckte es am Ende. Es funktioniert jetzt:

for i, v in enumerate(everything): 

    heatmap = ax[i].pcolor(v, cmap=plt.cm.Blues) 

    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) 

ax[0].invert_yaxis()