How to bring a scatter plot to the front of a 3d multiple plot

8 ビュー (過去 30 日間)
Daniele Giunta
Daniele Giunta 2023 年 9 月 7 日
コメント済み: Daniele Giunta 2023 年 9 月 8 日
Good morning!
I would like to realize this plot with the scatter points covering the line plot (for istance, the green point 35 should cover the black line of the plot, as the 32 does). How can i do? Was trying with the children function but it seems doesnt work with this 3d plot.

回答 (1 件)

VINAYAK LUHA
VINAYAK LUHA 2023 年 9 月 7 日
Hi Daniele,
As per my understanding you wish to superimpose the scatter plot over the line plot,such that line plot lines are not visible inside the scatter plot points, this can be done by plotting the grid-line plot first followed by the scatter points plot -
In the following code if the scatterplot is plotted first, the line plot lines are still visible over the points
xInterval = 5;
yInterval = 5;
zDistance = 2;
[xGrid, yGrid] = meshgrid(-10:xInterval:10, -10:yInterval:10);
zGrid = zDistance * ones(size(xGrid));
figure;
scatter3(xGrid, yGrid, zGrid,100,MarkerFaceColor="flat"); %line 9
hold on
surf(xGrid, yGrid, zGrid,FaceColor="none",LineWidth=1); %line 11
hold off
However, if you do the opposite, plot line plot first and then the scatter plot ,i.e switch places of line 9 and 11, you get the desired result.
Hope this helps
  3 件のコメント
VINAYAK LUHA
VINAYAK LUHA 2023 年 9 月 8 日
Hi Daniele,
Thanks for the update, Is it possible to share some code here ?
Daniele Giunta
Daniele Giunta 2023 年 9 月 8 日
Sure! I can't give you the scatter coordinates because they are in an excel file, but i think it doesn't matter to solve this graphic problem. This is the code (probably it could be so much better):
sens=readmatrix("Sens.xlsx");
% Vertical lines
p1 = [linspace(0,0,2); linspace(0.6,0.6,2); linspace(-3,0,2)];
p2 = [linspace(0,0,2); linspace(5.6,5.6,2); linspace(-3,0,2)];
p3 = [linspace(0,0,2); linspace(10.6,10.6,2); linspace(-3,0,2)];
p4 = [linspace(18,18,2); linspace(0.6,0.6,2); linspace(-3,0,2)];
p5 = [linspace(18,18,2); linspace(5.6,5.6,2); linspace(-3,0,2)];
p6 = [linspace(18,18,2); linspace(10.6,10.6,2); linspace(-3,0,2)];
% Horizontal lines
t1 = [linspace(0,0,2); linspace(0,11.2,2); linspace(0,0,2)];
t2 = [linspace(4.5,4.5,2); linspace(0,11.2,2); linspace(0,0,2)];
t3 = [linspace(9,9,2); linspace(0,11.2,2); linspace(0,0,2)];
t4 = [linspace(13.5,13.5,2); linspace(0,11.2,2); linspace(0,0,2)];
t5 = [linspace(18,18,2); linspace(0,11.2,2); linspace(0,0,2)];
t6 = [linspace(0,18,2); linspace(0,0,2); linspace(0,0,2)];
t7 = [linspace(0,18,2); linspace(1.4,1.4,2); linspace(0,0,2)];
t8 = [linspace(0,18,2); linspace(2.8,2.8,2); linspace(0,0,2)];
t9 = [linspace(0,18,2); linspace(4.2,4.2,2); linspace(0,0,2)];
t10 = [linspace(0,18,2); linspace(5.6,5.6,2); linspace(0,0,2)];
t11 = [linspace(0,18,2); linspace(7,7,2); linspace(0,0,2)];
t12 = [linspace(0,18,2); linspace(8.4,8.4,2); linspace(0,0,2)];
t13 = [linspace(0,18,2); linspace(9.8,9.8,2); linspace(0,0,2)];
t14 = [linspace(0,18,2); linspace(11.2,11.2,2); linspace(0,0,2)];
figure;
% Line plot
for i=1:6
eval(['plot3(p' num2str(i) '(1,:),p' num2str(i) '(2,:),p' num2str(i) '(3,:),Color=[0 0 0],LineWidth=1.2)'])
hold on
end
for j=1:14
eval(['plot3(t' num2str(j) '(1,:),t' num2str(j) '(2,:),t' num2str(j) '(3,:),Color=[0 0 0],LineWidth=1.2)'])
end
% Scatter plot
scatter3(sens(1:31,1),sens(1:31,2),sens(1:31,3),250,'filled','r','MarkerEdgeColor','k','LineWidth',1.5)
scatter3(sens(36:41,1),sens(36:41,2),sens(36:41,3),250,'filled','b','MarkerEdgeColor','k','LineWidth',1.5)
scatter3(sens(32:35,1),sens(32:35,2),sens(32:35,3),250,'filled','MarkerFaceColor',[0.4660 0.8740 0.1880],'MarkerEdgeColor','k','LineWidth',1.5)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by