【问题标题】:Filling an area below a curve with a colormap defined by the function of the curve用曲线函数定义的颜色图填充曲线下方的区域
【发布时间】:2019-08-14 19:38:49
【问题描述】:

考虑以下情节:

在左侧,您可以使用patch 命令查看关于函数配置文件的圆圈填充

t = linspace(-pi,pi,100);
c = exp(-cos(t));
figure(1)
patch(cos(t),sin(t),c)
axis equal

在右侧,您可以看到沿左侧虚线轴的函数轮廓,该轮廓使用area 命令填充。

figure(2)
area(cos(t),c,0);

我要做的是用左面板中表示的颜色图定义的颜色填充曲线下方的区域(右面板)。结果应该是这样的

【问题讨论】:

    标签: matlab plot colors matlab-figure area


    【解决方案1】:

    我能想到的最接近的事情是:

    function q55322965
    % Evaluate the equation (half domain!)
    t = linspace(-pi,0,50);
    c = exp(-cos(t));
    
    % Turn vectors into a mesh:
    [TT,CC] = meshgrid(cos(t),c);
    
    % Clear all points that are above the curve:
    CC(CC > c) = NaN;
    
    % Fill in the rectangle between the chart and zero:
    CC(end+1,:) = 0;
    TT(end+1,:) = TT(end,:);
    
    % Plot:
    figure(); mesh(TT,CC,CC,'FaceColor','interp','EdgeColor','interp'); view([0,90]);
    

    产量:

    如果您希望在使用此方法进行绘图时看起来不那么锯齿,您可以增加t 中的分辨率。例如,如果我们在linspace 中使用500 而不是50,我们会得到:

    【讨论】:

    • 为什么只选择了半个域而不是整个域 [-pi,pi]?
    猜你喜欢
    • 2018-11-01
    • 1970-01-01
    • 2020-07-02
    • 2016-12-28
    • 1970-01-01
    • 2011-12-15
    • 2021-12-23
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多