2014-02-11 100 views
2

我想繪製另一個數據集的填充輪廓頂部的一個數據集的輪廓線。單獨繪製他們都看起來是正確的,但是當我在平時的方式將它們組合的情節看起來不正確:在contourf圖頂部覆蓋輪廓線

clc; clear all; close all; 

x = linspace(-2*pi,2*pi); 
y = linspace(0,4*pi); 
[X1,Y1] = meshgrid(x,y); 
Z1 = sin(X1)+cos(Y1); 

[X2,Y2] = meshgrid(x,y); 
Z2 = 1000*(sin(1.2*X2)+2*cos(Y2)); 

figure; 
contourf(X1,Y1,Z1); 
shading flat; 

figure; 
contour(X2,Y2,Z2,'k'); 

figure; 
contourf(X1,Y1,Z1); 
shading flat; 
hold on; 
contour(X2,Y2,Z2,'k'); 

enter image description here enter image description here enter image description here

回答

4

爲了解決這個問題,你必須使用caxis設置爲contourf情節限制:

clc; clear all; close all; 

x = linspace(-2*pi,2*pi); 
y = linspace(0,4*pi); 
[X1,Y1] = meshgrid(x,y); 
Z1 = sin(X1)+cos(Y1); 

[X2,Y2] = meshgrid(x,y); 
Z2 = 1000*(sin(1.2*X2)+2*cos(Y2)); 

figure; 
contourf(X1,Y1,Z1); 
shading flat; 
caxis([min(min(Z1)) max(max(Z1))]); 
hold on; 
contour(X2,Y2,Z2,'k'); 

可以更換min(min(Z1))max(max(Z1))與您想要的上限和下限。這導致了這個情節:

enter image description here

+0

我浪費了很多時間試圖弄清楚這一點,所以我想我會發布它有望節約他人同樣的陷阱。 – OSE