1
votes

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.

2
Don't know how, but what sort of plot? Just lines? Maybe an example plot, with the code to produce it, would be useful (edit your question)Steve
There are several ways to do so, but which one is the best is depend heavily on what it is that you want to hide? What shape it has? Is it constrained by a function(s)? is it related to the position in the axes? How do you define the area to hide?EBH
I am currently working with a contour plot, and I want to hide the part of the plotted levels that is below a certain curve, that could well be y=xPeter
It would be much easier to only plot the desired region, using logical indexing to set your condition. Show us the line(s) of code where you call the plot and we can show you how to achieve this.Wolfie
It has to be a posteriori due to this: I already coded the logical operations so as to eliminate the unwanted values from the plot. However, the contour plot makes a kind of "graphical interpolation" to draw the levels correctly, but passing across the unwanted area, though there are no points there.Peter

2 Answers

2
votes

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

1
votes

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