我用来绘制的所有三个变量都是大小为1x1x100
的矩阵。我正在使用此代码行绘制:
hold on;
for i=1:100
plot3(R_L(:,:,i),N_Pc(:,:,i),CO2_molefraction_top_of_window(:,:,i),'o');
xlabel('R_L');
ylabel('N_P_c');
zlabel('CO_2')
end
但是,我没有得到第三个轴,因此第三个变量CO2_molefraction_top_of_window
在图上。我可以知道我哪里错了吗?
除了上面的问题,但在同一主题上,我想知道是否有任何选项,我可以绘制4维图,就像可以使用plot3
绘制的3维图?
只是一个注意事项---你只需要做一次xlabel
ylabel
zlabel
命令(在循环之外)。
也:
1x1x100
而不仅仅是100x1
或1x100
?因为如果你将它们重塑为2D,你可以在一次点击中进行绘图。.
X = rand(1,1,100); % 1x1x100 X matrix
Y = rand(1,1,100); % 1x1x100 Y matrix
Z = rand(1,1,100); % 1x1x100 Z matrix
% Now, we could do a for loop and plot X(:,:,i), Y(:,:,i), Z(:,:,i),
% OR we can just convert the matrix to a vector (since it's 1x1x100 anyway)
% and do the plotting in one go using 'squeeze' (see 'help squeeze').
% squeeze(X) converts it from 1x1x100 (3D matrix) to 100x1 (vector):
plot3(squeeze(X),squeeze(Y),squeeze(Z),'o')
xlabel('x')
ylabel('y')
zlabel('z')
这给出了以下内容,您可以清楚地看到三个轴:
如果你想让图形显示为“更多3D”的网格线,那么试试grid on
(在matlab帮助文件中的示例中为plot3
,从Matlab提示中尝试help plot3
):
grid on
你将不得不更多地澄清“缺少第三轴”。
所以当使用plot3
时我遇到了同样的问题。出于某种原因,使用hold on
命令“展平”情节。我不确定为什么,但我怀疑它与hold on
在剧情上执行的操作有关。编辑:为了澄清,3d图仍然存在,但透视图被迫改变。如果使用“旋转3D”工具(带有围绕立方体的箭头的工具),您可以看到图形为3d,默认透视图是直的,因此只有两个轴可见并且看起来是平的。
我遇到了类似的问题,而且@ Drofdarb的hold on
似乎使一个轴变平。这是我的代码片段,希望这会有所帮助。
for iter = 1:num_iters:
% hold on;
grid on;
plot3(tita0,tita1, num_iters,'o')
title('Tita0, Tita1')
xlabel('Tita0')
ylabel('Tita1')
zlabel('Iterations')
hold on; % <---- Place here
drawnow
end
相反:
for iter = 1:num_iters:
grid on;
hold on; % <---- Not here
plot3(tita0,tita1, num_iters,'o')
title('Tita0, Tita1')
xlabel('Tita0')
ylabel('Tita1')
zlabel('Iterations')
% hold on;
drawnow
end