Matlab:Plot3没有显示第3轴

问题描述 投票:0回答:3

我用来绘制的所有三个变量都是大小为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维图?

matlab 3d plot 4d
3个回答
1
投票

只是一个注意事项---你只需要做一次xlabel ylabel zlabel命令(在循环之外)。

也:

  • 有什么理由你的矩阵是1x1x100而不仅仅是100x11x100?因为如果你将它们重塑为2D,你可以在一次点击中进行绘图。
  • “缺少第三轴”是什么意思?当我运行你的代码时(或者我尽可能接近,因为你没有提供可重现的例子),我确实得到了第3个轴:

.

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

你将不得不更多地澄清“缺少第三轴”。


4
投票

所以当使用plot3时我遇到了同样的问题。出于某种原因,使用hold on命令“展平”情节。我不确定为什么,但我怀疑它与hold on在剧情上执行的操作有关。编辑:为了澄清,3d图仍然存在,但透视图被迫改变。如果使用“旋转3D”工具(带有围绕立方体的箭头的工具),您可以看到图形为3d,默认透视图是直的,因此只有两个轴可见并且看起来是平的。


0
投票

我遇到了类似的问题,而且@ 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

enter image description here


相反:

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.