2013-04-17 44 views
3

我試圖讓顏色條居住在一系列四個子圖的右側。 我使用這個代碼,但酒吧的最後一個圖像相交如本圖problem重新定位顏色條或子圖

ax(1)=subplot(1,3,1);imagesc(stats.mean,[0 1]);colormap(jet(256)); title('mean'); 
ax(2)=subplot(1,3,2);imagesc(stats.median,[0 1]);colormap(jet(256)); title('median'); 
ax(3)=subplot(1,3,3);imagesc(stats.std,[0 1]);colormap(jet(256)); title('std'); 
h=colorbar; 
set(h, 'Position', [.8314 .11 .0581 .8150]); 
for i=1:3 
pos=get(ax(i), 'Position'); 
set(ax(i), 'Position', [pos(1) pos(2) 0.85*pos(3) pos(4)]); 
end; 
+0

我敢肯定有做這種正確的方式,但作爲一個快速解決您可以添加一個第四次要情節,然後進行'插曲(1, 4,4)'只有顏色條的空圖像... – Dan

+3

您正盲目應用在名爲[我如何爲子圖創建一個顏色條並將顏色條與圖形關聯而不是每個單獨的軸關聯的技術解決方案中提出的解決方案在MATLAB 7.7(R2008b)?](http://www.mathworks.co.uk/support/solutions/en/數據/ 1-16FPP)。 該解決方案所做的是調整子插槽大小並重新定位顏色條。你可以簡單地用'set(h,'Position',[.87 .11 .0581 .8150]);''來進一步推動顏色條。請注意**。87 **。 – Oleg

+0

@丹你能告訴我如何做到這一點? – Tak

回答

3

我提出一個不同的方法。

假設你正密謀如下:

ax(1) = subplot(1,3,1);imagesc(rand(100,1),[0 1]); 
ax(2) = subplot(1,3,2);imagesc(rand(100,1),[0 1]); 
ax(3) = subplot(1,3,3);imagesc(rand(100,1),[0 1]); 

我建議乾脆復位第三次要情節將由colorbar影響的尺寸和伸展的身影,包括增加的彩條。

% Get positions of all the subplot 
posa = get(ax,'position'); 
h = colorbar; 

% Reset ax(3) position to before colorbar 
set(ax(3),'position',posa{3}) 

% Set everything to units pixels (avoids dynamic reposition) 
set([ax h],'units','pix') 

% Widen figure by a factor of 1.1 (tweak it for needs) 
posf = get(gcf,'position'); 
set(gcf,'position',[posf(1:2) posf(3)*1.1 posf(4)]) 

結果

enter image description here