how to change color of dot in a 3D scatter plot?
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!