【问题标题】:Shading between vertical lines in MATLABMATLAB中垂直线之间的阴影
【发布时间】:2011-06-09 13:54:31
【问题描述】:

我确定这是一个简单的问题,但我似乎无法弄清楚。我有这个情节

我想添加垂直线并在其间添加阴影区域以突出显示数据区域。我觉得我应该能够使用 area 函数来做到这一点,但似乎无法弄清楚。日期和值都是双精度的,并且是两个单独的向量,如果这有所不同的话。任何帮助将不胜感激。

【问题讨论】:

    标签: matlab area


    【解决方案1】:

    关于在绘图中对区域进行着色的非常基本的示例。 Shading an area boundered by a curve 可能也很有趣。

    figure;
    ha = area([4 6], [10 10]);
    hold on
    plot(1:10, 1:10,'r')
    axis([1 10 1 10])
    hold off
    

    【讨论】:

    • 非常感谢。 area 的文档太混乱了。
    【解决方案2】:

    除了area,你也可以使用fill,这样在使用上会更直观一些。

    figure;
    plot(1:10, 1:10,'r');
    
    % Define the "shading"
    % Note how each x_points(i) corresponds to y_points(i)
    x_points = [5, 5, 7, 7];  
    y_points = [0, 10, 10, 0];
    color = [0, 0, 1];
    
    hold on;
    a = fill(x_points, y_points, color);
    a.FaceAlpha = 0.1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-20
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2019-07-10
      • 2015-01-23
      相关资源
      最近更新 更多