如何在 MATLAB 的 scatter3 图中绘制两点之间的线?
How to plot a line between two points in a scatter3 plot in MATLAB?
我正在使用以下代码生成散点图:
X = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3];
Y = [0,0,0,20,20,20,40,40,40,60,60,60,80,80,80,];
Z1 = [10,-48.7863,-73.3457, -68.3091, -142.0666,...
12, -35.7863, -23.347, -29.3091,-141.0660,...
13,3.2137,-10.3457,-33.3091,-128.0666]
Z2 = [2,8.2137,-2.3457, 46.6909, 12.9334,...
10,11.2137, 19.6543,35.6909, 45.9334,...
-1,16.2137,37.6543,50.6909,34.9334]
figure;scatter3(X,Y,Z1,'filled'); hold on;
scatter3(X,Y,Z2,'filled')
结果如下图:
我想要的是每个蓝点和红点之间的垂直线。
示例性输出可能如下所示:
我尝试使用 line
函数,但是我不确定如何构建向量。
我试过了:
line(X,Y,Z1) % will only connect the blue dots
line(X,Y,Z2) % will only connect the red dots
line(X,Y,Z1:Z2) % will give an error that the vectors must be the same length
您必须 vertically concatenate your Z1
and Z2
data so that each column defines a line 才能绘制。您还必须以相同的方式复制 X
和 Y
:
line([X; X], [Y; Y], [Z1; Z2], 'Color', 'r');
结果(添加到您的散点图):
我正在使用以下代码生成散点图:
X = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3];
Y = [0,0,0,20,20,20,40,40,40,60,60,60,80,80,80,];
Z1 = [10,-48.7863,-73.3457, -68.3091, -142.0666,...
12, -35.7863, -23.347, -29.3091,-141.0660,...
13,3.2137,-10.3457,-33.3091,-128.0666]
Z2 = [2,8.2137,-2.3457, 46.6909, 12.9334,...
10,11.2137, 19.6543,35.6909, 45.9334,...
-1,16.2137,37.6543,50.6909,34.9334]
figure;scatter3(X,Y,Z1,'filled'); hold on;
scatter3(X,Y,Z2,'filled')
结果如下图:
我想要的是每个蓝点和红点之间的垂直线。
示例性输出可能如下所示:
我尝试使用 line
函数,但是我不确定如何构建向量。
我试过了:
line(X,Y,Z1) % will only connect the blue dots
line(X,Y,Z2) % will only connect the red dots
line(X,Y,Z1:Z2) % will give an error that the vectors must be the same length
您必须 vertically concatenate your Z1
and Z2
data so that each column defines a line 才能绘制。您还必须以相同的方式复制 X
和 Y
:
line([X; X], [Y; Y], [Z1; Z2], 'Color', 'r');
结果(添加到您的散点图):