2016-04-04 7 views
2

Ich habe zwei Farbbalken im selben Bild mit this submission auf Dateiaustausch.colorbar oastoutside vs westoutside

enter image description here

Die Position des ersten colorbar wird durch gesetzt:

colorbar('WestOutside') 

die Position des zweiten von: mehr

colorbar('EastOutside') 

Weiß jemand, warum die erste ist ?

Beim Betrachten der Matlab documentation schien es mir, dass sie gleich sein sollten. Was vermisse ich?

Das Skelett des Codes ist die folgende:

%define coordinates of the nodes 
theta=linspace(0,2*pi,33); 
[x,y]=pol2cart(theta,1); 

%define colormap of the links 
cm = winter; 
colormap(cm); 

%plot the links 
for ii=1:N 
quiver(...) 
end 

%place the first colorbar 
hcb=colorbar('EastOutside'); 

%freeze the first colorbar 
cbfreeze(hcb); 


%define the second colormap 
cm = autumn; 
colormap(cm); 

%plot the dots 
for ii=1:N 
plot(...) 
end 

%place the second colorbar 
hb=colorbar('EastOutside'); 
+0

Ich schlage vor, Sie ein bisschen mehr Code, der zeigt, wie Sie Ihre Handlung – Dan

+0

Nice Grundstück! Ich würde versuchen, die Achse zuerst zu erstellen, dann fügen Sie Ihre Farbleisten hinzu, die diese Achse explizit angeben, dann führen Sie Ihre Plots auch explizit die Achse angeben. Es sieht so aus, als ob die erste Colormap erstellt wird, bevor die Achse befüllt wird. Daher kann die Größe der Diagramme geändert werden. –

+0

@HughNolan danke, aber ich weiß nicht, wie es geht. Wie kann ich zuerst die Achse erstellen und dann die Handlung machen? – shamalaia

Antwort

1

Der Schlüssel ist, zwei verschiedene Achsen eingesetzt werden. Basierend auf Ihren Code:

%define coordinates of the nodes 
theta=linspace(0,2*pi,33); 
[x,y]=pol2cart(theta,1); 

%plot the links 
close 
figure; 
for ii=1:100 
    quiver(x,y) 
end 
%define colormap of the links 
ax1 = gca; 
colormap (ax1,winter) 
%place the first colorbar 
hcb=colorbar(ax1,'EastOutside'); 
%this is tentative, just to get the axes right position: 
hb=colorbar(ax1,'WestOutside'); 
pos = ax1.Position; 
hb.delete 
% second colorbar 
ax2 = axes; 
colormap (ax2,autumn) 
hb=colorbar(ax2,'WestOutside'); 
ax2.Position = pos; 
axis off 
ax1.Position = pos; 

Es schafft dies: enter image description here

mit MATLAB 2015a.

Verwandte Themen