Search code examples
matlabmatlab-figure

Erase area of matlab plot a posteriori


Is it possible to erase an area of a plot, without direct manipulation of the data that you input to the plot (a posteriori)?

E.g. Area below y=x while the area above is kept.


Solution

  • You can use area with white face color to blank the area of the plot below a given line:

    t = linspace(0,20,500);
    plot(t, sin(t)) % example plot
    yl = ylim;
    hold on
    y = .4 - t * .05; % example limit line
    area(t, y, yl(1), 'Facecolor', 'w', 'edgecolor', 'none');
    

    enter image description here