scatterplot shows RowIDs as points and points as a color map
1 view (last 30 days)
Show older comments
Hi,
I would like to plot a scatter plot but I would like to show the points in the scatterplot by point IDs. For example, if I have RowIDs from 1 to 10, I have two columns X and Y. I want to show a scatter plot of X and Y but the points should show the point IDs (1-10). Also, I would like to include a colormap so that these points have a color spectrum.
Can anybody suggest me a method how to implement in MATLAB? (Please see the image of what I want to do)
Thanks in advance.
0 Comments
Accepted Answer
arich82
on 29 May 2014
Edited: arich82
on 29 May 2014
Would something like this work?
n = 30; % number of data points
cmap = jet(n); % builtin colormap; could choose another...
C = mat2cell(cmap, ones(1, size(cmap, 1)), 3); % reshape for 'set'
% dummy data
k = [1:n].';
t = (k - 1)/n;
r = (t - 1).*cos(2*pi*2*sqrt(t));
%
x = 10*((1 + r)/2);
y = x;
z = t;
%figure('WindowStyle', 'docked');
%surf([x, x], [y, y], [z - eps, z + eps], 'EdgeColor', 'interp');
% plot numerical data
hf = figure('WindowStyle', 'docked');
ha = axes;
axis(ha, [0, 10, 0, 10]);
ht = text(x, y, num2str(k));
set(ht, {'Color'}, C)
set(ht, 'FontWeight', 'bold');
colormap(cmap);
colorbar;
Note: using the 'set' command with cell arrays can be a little cumbersome (in my opinion), as there seem to be a number of gotchas; you could just as easily loop through ht:
for ind = 1:n
set(ht(ind), 'Color', cmap(ind, :));
end
Let me know if this works for you.
--Andy
5 Comments
arich82
on 8 Jul 2014
I'm confused: I though you said "I would like to include a colormap so that these points have a color spectrum". Do you no longer want this? If not, simply omit the building and use of C.
It appears,
set(ht, {'Color'}, C)
is how you're changing the text color. Try omitting that line (place a % in front), or try
set(ht, 'Color', 'k'); % equvivalent to set(ht, 'Color', [0, 0, 0]);
to change all the text to black.
I hope this helps; please clarify what you're expecting if it doesn't.
More Answers (0)
See Also
Categories
Find more on Orange 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!