Whiteout regions on Contour Plot
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
laoliu102
am 14 Dez. 2017
Kommentiert: Walter Roberson
am 31 Mär. 2023
I don't want to display certain regions of the contour plot. How can I whiteout these regions on the contour plot? The interpolated data fills the entire space while the real data has blank regions that physically don't contain anything. These blank regions are the regions that I don't want to display on the contour plot. I have attached the two plots.
I have the scatter plot data as x,y,z arrays and the interpolated data for the contour plot as x,y,z matrices.
Any help/suggestion is welcomed and appreciated. Thank you.
![](/matlabcentral/answers/uploaded_files/98567/question.jpg)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Dez. 2017
My recommendation would be to set the interpolated data to nan in those regions before doing the contour plot.
However, since you have scattered data, you have the challenge of determining which points are "near enough" to explicit scattered data that they should validly be interpolated, and which points are instead to be interpreted as being too far from the scattered data and so should be interpreted as being outside the map.
You could consider a pdist2() approach but it appears you have a fair bit of data, so that would not be computationally feasible. You might be able to take advantage of kd-tree approaches; https://www.mathworks.com/help/stats/classification-using-nearest-neighbors.html
6 Kommentare
Walter Roberson
am 14 Dez. 2017
cutoff_distance = 6.28; %set as appropriate
[xi,yi] = meshgrid(300:20:2200, 300:20:1800);
zi = griddata(xn, yn, zn, xi, yi);
DT = delaunayTriangulation(xn, yn);
[vi, d] = nearestNeighbor(DT, xi(:), yi(:));
mask = d > cutoff_distance;
zi(mask) = nan;
Weitere Antworten (1)
Muhammad Usman
am 6 Nov. 2019
I have got the same problem but mine was a little bit simple. I use the built-in MATLAB function "scatterInterpolant" to plot a contour. The plot is shown below.
![Sigma_xx.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247079/Sigma_xx.jpeg)
It's s stress contour and the ellipse is an empty space and there are no nodes inside the ellipse. I want the ellipse to be whiteout. Somehow I managed to set the values inside the ellipse to be zero (because I can't delete them) and I got the following result
![Sigma1_xx.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247080/Sigma1_xx.jpeg)
P.S. I use the fill command to fill the ellipse with white color but that's not a proper way to do it.
8 Kommentare
Jiandong
am 31 Mär. 2023
Maybe you can use the inpolygon function
[in,on] = inpolygon(x_list,y_list,ellipse_x,ellipse_y);
for i = 1:length(x_list)
if(in(i))
ellipse_x(i)=NaN;
ellipse_y(i)=NaN;
end
end
Walter Roberson
am 31 Mär. 2023
That suggests to me that you could use the shorter
[in,on] = inpolygon(x_list,y_list,ellipse_x,ellipse_y);
ellipse_x(in) = NaN;
ellipse_y(in) = NaN;
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!