how to change color of dot in a 3D scatter plot?

13 vues (au cours des 30 derniers jours)
Christophe Nell
Christophe Nell le 4 Août 2015
I have done a scatter plot and when I select a point, I want that the color of this point takes another color. My function work in 2D but when I had a third dimension, it doesn't work.
function test()
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%img = ones(300); % image to display
%h = imshow(img,'Parent',gca);
%set(h,'ButtonDownFcn',{@ax_bdfcn});
fig = figure;
a = [1 2 3 4 5];
b = [2 3 4 5 6];
c = [2 2 3 3 3];
name = {'one', 'two', 'three', 'four', 'five'};
DCM_Data.Position = [a; b; c];
DCM_Data.Title = name;
scatter3(a, b, c, 'filled')
dcm_obj = datacursormode(fig);
set(dcm_obj,'UpdateFcn', {@myupdatefcn, DCM_Data});
end
function txt = myupdatefcn(empt,event_obj, DCM_Data)
pos = get(event_obj,'Position');
[dummy, index] = min(((pos(1) - DCM_Data.Position(1, :)).^2) + ...
((pos(2) - DCM_Data.Position(2, :)).^2));
nameNumber = DCM_Data.Title{index};
txt = {nameNumber};
hold on
scatter3(pos(1), pos(2), pos(3), 'r', 'filled');
end
In 2D, scatter(pos(1), pos(2), 'r', 'filled'); change the color of the dot. In 3D nothing appends. Should I first try to remove the dot? how?
Thank you

Réponse acceptée

Christophe Nell
Christophe Nell le 4 Août 2015
I solved the problem by plotting the dot separately for x=1:1:size(a) dot(x) = scatter3(a(x), b(x), c(x)) end
In function myupdatefcn(empt,event_obj, DCM_Data): delete(dot(index))

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by