Peter
Peter

Reputation: 71

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.

Upvotes: 1

Views: 73

Answers (2)

EBH
EBH

Reputation: 10440

Here's a way to do this by plotting only what is needed, and replace all other values with nan:

[X,Y,Z] = peaks;
Z(X>Y) = nan;
contour(X,Y,Z,20)

covered_contour

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112679

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

Upvotes: 2

Related Questions