scatterplot shows RowIDs as points and points as a color map

1 view (last 30 days)
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.

Accepted Answer

arich82
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
Damith
Damith on 4 Jul 2014
Hi,
Thanks all for your comments. I made this to work. Please look at the following code. But I need to show the points (as numbers) in black color. But it is showing in different colors according to the colormap. How can I make it show all the points (as numbers) in black color.
Thanks in advance.
n = 6; % number of data points
cmap = jet(n); % builtin colormap; could choose another...
C = mat2cell(cmap, ones(1, size(cmap, 1)), 3); % reshape for 'set'
k = [1:n].';
marker_size = 25;
marker_type = 's'
xlim([2 6]),ylim([2 6])
ht = text(Ob_All_avg, WGEN_All_avg, num2str(k));
set(ht, {'Color'}, C)
set(ht, 'FontWeight', 'bold','FontSize',18,'edgecolor','none');
colormap(cmap);
box on
line([2,6],[2,6],...
'linewidth',0.6,...
'color',[1,0,0],'LineStyle','--');
set(gca,...
'xlim',[2,6],...
'ylim',[2,6]);
axis square;
xlabel('TRMM (1998-2012)','FontSize',14)
ylabel('WGEN generated 10000 yrs','FontSize',14)
title('Daily Mean','FontSize',14)
arich82
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps 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!