Cutting line/contour line in graph

5 views (last 30 days)
Luh Putri Adnyani
Luh Putri Adnyani on 17 May 2021
Commented: Adam Danz on 20 May 2021
Hi all,
Does anyone here know how to cut the line/contour line on the graph as shown in one of the papers below?
while the original result is like the image below.
I tried to use a box plot like the code below, but the contour line still continue to depth -10m, not stop in the plot box. does anyone can provide ideas how to solve it?
x=ncread('roms_his.nc','x_rho')/1000;
z=ncread('roms_his.nc','s_rho').*(10);
salt=ncread('roms_his.nc','salt');
[xo,zo]=meshgrid(x(:,1),z);
contour(xo',zo',squeeze(salt(:,1,:,1)),'ShowText','on');
xticks(0:10:100);
x1=0;
x2=100;
y1=-0;
y1=-10;
y2=-0.5;
y2=-5;
y3=0;
x_box = [x1, x1, x2, x2, x1];
y_box = [y1, y3, y3, y2, y1];
plot(x_box, y_box, 'b-', 'LineWidth', 3);
hold on
contour(xo',zo',squeeze(salt(:,1,:,1)),'ShowText','on');
hold off
xticks(0:10:100);
xlabel('Distance, km')
ylabel('Depth, m')
title(['Initial salinity distribution for estuary simulations'])
Thanks before.

Answers (1)

Adam Danz
Adam Danz on 17 May 2021
Edited: Adam Danz on 17 May 2021
Since you know the coordinate of the blue trapazoid, you can create a white patch object that is equal to the area under the trapazoid and plot the white patch on top of the contour object but under the blue trapazoid object. That will hide any contour lines below the blue line.
Use patch or fill.
Alternatively, with a lot more work you could get the coordinate values of the contour lines using any number of file exchange submissions and then eliminate any coordinates below the blue line but then the contour lines may not touch the blue line.
  2 Comments
Adam Danz
Adam Danz on 20 May 2021
Glad I could help.
Consider accepting the answer (blue accept button).

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!