2015-06-19 112 views
1

我正在使用python繪製3個子圖的圖。我想設置的顏色表是熱的每個插曲,我的代碼是這樣的:python:如何設置3個子圖的相同顏色圖

fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(20,15)) 
count = 0 
for ax in axes.flat: 
    count += 1 
    if count == 1: 
     im = ax.imshow(data_in_array, interpolation='nearest',vmin=0, vmax=150) 
     ax.set_xticks(range(24)) 
     ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15) 
     ax.set_yticks(range(8)) 
     ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15) 
     ax.set_title('arriving hours of travel survey',fontsize=15) 
     plt.hot() 

    if count == 2: 
     im = ax.imshow(data_out_array, interpolation='nearest',vmin=0, vmax=150) 
     ax.set_xticks(range(24)) 
     ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15) 
     ax.set_yticks(range(8)) 
     ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15) 
     ax.set_title('leaving hours of travel survey',fontsize=15) 
     plt.hot() 

    if count == 3: 
     im = ax.imshow(data_stay_array, interpolation='nearest',vmin=0, vmax=150) 
     ax.set_xticks(range(24)) 
     ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15) 
     ax.set_yticks(range(8)) 
     ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15) 
     ax.set_title('stay hours of travel survey',fontsize=15) 
     plt.hot() 


fig.subplots_adjust(right=0.8) 
cbar_ax = fig.add_axes([0.75, 0.1, 0.03, 0.8]) 
fig.colorbar(im, cax=cbar_ax) 
plt.show() 

然而,我的情節是這樣的: enter image description here

第一個是不是熱的顏色表,任何想法修復?

+1

由於您正在使用'for'循環,所以'colorbar'的映射被視爲最後一個子圖。 – ThePredator

回答

1

當您在軸上繪圖時,您需要在繪圖之前設置全局顏色條。因此,您需要在第一個ax.imshow()之前撥打plt.hot()

+0

謝謝!有用 – gladys0313

相關問題