根据距离原点的距离,在3D Matlab Plot上更改数据点的颜色

时间:2015-12-20 21:44:54

标签: matlab plot 3d matlab-figure

我有x,y,z位置数据,我想在3d MATLAB图中绘制,但我想根据它们与原点的距离来改变数据点的颜色。我目前的代码是这个脚本的一部分:

figure

% Initialise plot, get handle to object and set style to dots
h = plot3(NaN,NaN,NaN,'.'); 
% Fix axes
axis([min(X3D(:)) max(X3D(:)) min(Y3D(:)) max(Y3D(:)) min(Z3D(:)) max(Z3D(:))]); 

% Loop over all elements of XS3D
for ii = 1:length(X3D)
    % pause for animation behaviour
    pause(0.01)
    % Set data of graph
    set(h, 'XData', X3D(1:ii), 'YData', Y3D(1:ii), 'ZData', Z3D(1:ii));      
end

当然,这只会在任何时候用单一颜色绘制数据点,这不是我想要的。

我应该注意到我在2D绘图中实现了这一点,尽管离散的颜色变化不连续,如下所示:

%Plot starts here
figure

% Set x and y limits of the plot
xlim([min(X(:))-1 max(X(:))+1])
ylim([min(Y(:))-1 max(Y(:))+1])

% Plot point by point
for k = 1:numel(X)
    if (X(k)^2 + Y(k)^2) < 500
        plot(X(k),Y(k),'.g') 

    elseif (X(k)^2 + Y(k)^2) >= 500 && (X(k)^2 + Y(k)^2 < 1000)
        plot(X(k), Y(k),'.','color',orange)

    else
        plot(X(k), Y(k), '.r')
    end

% MATLAB pauses for 0.001 sec before moving on to execute the next 
% instruction => thus creating animation effect
pause(0.001);  

end

然而,上面似乎仅适用于2d图,如果我尝试类似于此处的代码,我将情节交换为plot3,由于某种原因,我仍然没有得到3d图。

0 个答案:

没有答案
相关问题