scatter plot and definition of contour levels in z coordinate
2 次查看(过去 30 天)
显示 更早的评论
Dear all,
I have created a scatter plot from x, y and z coordinates for a bed topography characterization around vertical structures. In plane, they have different colors according to the z range of values. The scatter plot do not seem to be a discrete representation of the data due to the high number of points.
Now, I would like to know if it is possible or not to create a contour plot, i.e., to define contour lines in the same plot (within the scatter plot). If yes, how can I do it? I have tried the contour and contourf functions but it always returns an error as the x and the y coordinates are columns of data and not matrices.
Thank you in advance!
Kind regards
0 个评论
回答(2 个)
Kelly Kearney
2015-9-10
An alternative to gridding your data would be to use one of the scattered-data contouring functions from the File Exchange. These work best when your data is not too noisy (relative to the contour levels you choose):
% Fake data
x = randn(500,1);
y = randn(500,1);
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2); % peaks
% Plot
tri = delaunay(x,y);
tricontour(tri,x,y,z,-6:6);
hold on;
scatter(x,y,[],z,'filled');
8 个评论
Kelly Kearney
2015-9-11
编辑:Kelly Kearney
2015-9-11
Well, that's not a contour plot. I think using a scattered interpolant and pcolor/image will get what you want. I chose natural neighbor interpolation with no extrapolation, which looks similar to your example:
% Fake data
x = randn(500,1);
y = randn(500,1);
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2);
% Plot
xg = linspace(min(x), max(x), 100);
yg = linspace(min(y), max(y), 100);
[xg,yg] = meshgrid(xg,yg);
F = scatteredInterpolant([x y], z, 'natural', 'none');
zg = F(xg,yg);
hp = pcolor(xg,yg,zg);
shading flat;
hold on;
hs = scatter(x,y,2,z,'filled');
set(hs, 'markeredgecolor', 'w');

Lihuang Zhu
2022-6-15
Exactly what I am looking for. I just don't know the terminology of this kind of plot. Thank you!
Walter Roberson
2015-9-8
Assuming that you have a column of data corresponding to each (x, y, z) triple... call the matrix xyzV
xspacing = 0.01;
yspacing = 0.01;
zspacing = 0.001;
x = xyzV(:,1);
y = xyzV(:,2);
z = xyzV(:,3);
V = xyzV(:,4);
xidx = 1 + round((x - x(1))/xspacing);
yidx = 1 + round((y - y(1))/yspacing);
zidx = 1 + round((z - z(1))/zspacing);
Vcuboid = accumarray([xidx, yidx, zidx], V);
After that you are left with the question of how you want to take a contour plot of a cuboid of values. You might want to use isosurface() or you might want to use slice()
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!