【问题标题】:How to customize contour lines in Matlab?如何在 Matlab 中自定义轮廓线?
【发布时间】:2019-04-02 16:09:40
【问题描述】:

我正在准备一个等高线图,我应该在其中突出显示特定级别的等高线。例如,我的等高线值介于 -1 和 1 之间,我想突出显示对应于值 0 的线。我尝试使用以下过程来做到这一点,

[M,c]=contourf(longitude,latitude,delta',-1:0.2:1);
s=size(c.LevelList,2);
for i=1:s
  if (c.LevelList(i)==0)
  c.LevelWidth=2;
  end;
end;

但是,它对等高线图没有任何作用。任何人都可以帮助我进行适当的程序吗?

【问题讨论】:

    标签: matlab


    【解决方案1】:

    我建议在您想要的级别上简单地使用contour 以在初始contourf 之后突出显示,如下所示:

    % Input.
    x = linspace(-2*pi, 2*pi, 101);
    y = x + pi;
    [X, Y] = meshgrid(x, y);
    Z = 0.5 * (sin(X) + cos(Y));
    
    % Levels to plot with contourf.
    levelsf = -1:0.2:1;
    
    % Levels to highlight.
    levels = [0 0.3];
    
    figure(1);
    hold on;
    
    % Contourf all levels.
    contourf(X, Y, Z, levelsf);
    
    % Highlight levels with simple contour.
    contour(X, Y, Z, levels, 'r', 'LineWidth', 2);
    
    hold off;
    

    为了突出显示levels = [0 0.3],您将获得:

    【讨论】:

    • 谢谢!为了仅突出显示我使用 [0 0] 的 0 轮廓线,它没有任何问题。
    猜你喜欢
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 2021-11-22
    相关资源
    最近更新 更多