scatter plot on top of surface has garbled points

6 Ansichten (letzte 30 Tage)
mkarikom
mkarikom am 15 Mai 2020
Kommentiert: Ameer Hamza am 15 Mai 2020
I have the following code that overlays a scatter plot on a surface.
Notice that some of the rounded points are chopped off.
figure
scatter(rand(20,1)*10,...
rand(20,1)*20,...
'o', 'LineWidth',5, ...
'MarkerFaceColor', 'black', ...
'MarkerEdgeColor', 'black')
hold on
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)
view(2)
axis equal square;
Here is the output:

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 15 Mai 2020
You are using surf(), which plots a 3D surface. scatter() draws points at z=0, so if the surface lies above, or intersect the point, it becomes invisible or partially visible. Since you are using view(2), so there is no need to create a 3D surface. You can get same visual using pcolor
figure
hold on
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
pcolor(X,Y,Z)
view(2)
scatter(rand(20,1)*10,...
rand(20,1)*20,...
'o', 'LineWidth',5, ...
'MarkerFaceColor', 'black', ...
'MarkerEdgeColor', 'black')
axis equal square;

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by