【问题标题】:Overlaying contour lines on top of contourf plot在等高线图上叠加等高线
【发布时间】:2014-02-11 20:13:56
【问题描述】:

我试图在另一个数据集的填充轮廓之上绘制一个数据集的轮廓线。单独绘制它们看起来都正确,但是当我以通常的方式将它们组合起来时,它们看起来不正确:

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');

【问题讨论】:

    标签: matlab plot contour


    【解决方案1】:

    要解决此问题,您必须使用 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)) 替换为您想要的上限和下限。这导致了这个情节:

    【讨论】:

    • 我浪费了很多时间试图弄清楚这一点,所以我想我会发布它以希望将其他人从同一个陷阱中拯救出来。
    猜你喜欢
    • 2023-02-04
    • 2021-12-21
    • 2018-11-19
    • 2017-07-24
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多