scatterplot shows RowIDs as points and points as a color map
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
arich82
2014-5-29
编辑:arich82
2014-5-29
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 个评论
arich82
2014-7-8
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!