2016-12-05 7 views
2

Ich zeichne verschiedene Abbildung in Teilplots mit dem folgenden Verfahren.Verwenden Sie die gleiche Farbleiste für verschiedene Unterplots in Matplotlib

fig = figure(figsize=(10,11)) 
subplots_adjust(wspace=0.5,hspace=0.2) 
iplot = 330 
for i in range(9): 
    iplot += 1 
    ax = fig.add_subplot(iplot) 
    ## Comparison Mreal - Real 
    tmp = REAL[REAL.days==days[i]] 
    tmp = tmp.score 
    tmp = np.array(tmp) 
    tmp = tmp.reshape(len(xv), len(br)) 
    im = plt.imshow(tmp, interpolation='nearest', cmap='gnuplot', vmin = 0, vmax = 1, extent=[0.05,0.5,1,0.05], 
       aspect=0.5) 
    xtmp = [0.05, 0.2, 0.3, 0.4, 0.5] 
    plt.xticks(xtmp) 
    ytmp = [0.05, 0.2, 0.4, 0.6, 0.8, 1.0] 
    plt.yticks(ytmp) 
    ax.grid(False) 
divider = make_axes_locatable(plt.gca()) 
cax = divider.append_axes("right", "5%", pad="3%") 
plt.colorbar(im, cax=cax) 
plt.tight_layout() 

und das ist, was ich bekommen:

enter image description here

Allerdings Ich mag würde das gleiche colorbar für alle Handlungsstränge haben, für istance auf der rechten Seite der Figur.

Antwort

2

Blick auf das folgende Beispiel:

import matplotlib.pyplot as plt 

fig, axes = plt.subplots(nrows=3, ncols=3) 
for ax in axes.flat: 
    im = ax.imshow(np.random.random((6,6)), interpolation='nearest', cmap='gnuplot', 
    vmin=0, vmax=1, extent=[0.05,0.5,1,0.05],aspect=0.5) 

fig.subplots_adjust(right=0.8) 
# put colorbar at desire position 
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]) 
fig.colorbar(im, cax=cbar_ax) 

plt.show() 

enter image description here

Verwandte Themen