我试图将一个数据集的轮廓线绘制在另一个数据集的填充轮廓之上。单独绘制它们看起来都是正确的但是当我以通常的方式将它们组合起来时,情节看起来不正确:
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');
答案 0 :(得分: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))
替换为您想要的上限和下限。这导致了这个情节: