Changing the colour intensity of a 2D plot

Hi,
I'm plotting lat long data on a map like this.
I'm using the plotm() function:
plotm(x,y,'LineStyle','none','Marker','o','MarkerSize',20);
I'm trying to change the colours so that areas with more data are a different colour. I would like the intensity of the colour to change with the amount of data points.
Would anybody know how I could achieve this?
Thanks

Answers (2)

plotm() cannot have different colors within any one line (column of data).
There are tricks for using patch() for drawing very narrow lines.
It appears to me that your data is sufficiently dense that you could use scatterm() and have the output look relatively continuous. scatterm() accepts a matrix of colors, one RGB row per point.

11 Comments

Hi Walter,
Thank you for your response. Can I ask one further question.
Would I need to count how many of each individual Lat long pair I have in order to do this? I have 100,000+ plus points and I am not sure how I would do that.
Is there anyway I could get matlab to shade areas with higher intensities a different colour?
This is an example of what I'm trying to achieve:
This is the code I'm using.
ax = worldmap('ireland');
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(ax, land, 'FaceColor', [0.5 0.7 0.5])
hold on
plotm(x,y,'LineStyle','none','Marker','o','MarkerSize',20);
Thank you
Regards
John
[ux, uxa, uxb] = unique(x);
[uy, uya, uyb] = unique(y);
counts = accumarray( [uxb(:), uyb(:)], 1 );
maxcount = max(counts(:));
relative_counts = counts(sub2ind(size(counts), uxb, uyb)) ./ maxcount;
rgbarray = [zeros(length(x), 2), relative_counts(:)];
pointsize = 10; %adjust as needed
scatterm( x, y, pointsize, rgbarray );
Thank you for your help Walter, much appreciated.
Hello Walter,
I have been using the code that kindly wrote for me a couple of weeks ago.
I was wondering if there was a way to make the color more variable? At the moment is displaying primarily in all black with a little blue at a very dense area. Would this be possible?
Many thanks
J
Could I ask you to post an image of
hist(relative_counts, 32)
also, could you show
mean(relative_counts)
std(relative_counts)
size(relative_counts)
Hello Water,
The mean is 0.067 The std is 0.2105 The size is 391994
Here is the Hist of relative counts.
I have different amounts of data for different maps. I assume that the amount of data influence the color. I have more data if required.
Thanks for the help
All the best
J
That's fairly badly skewed.
I'm not sure how well it will work for display purposes, but try
rgbarray = [zeros(length(x), 2), relative_counts(:).^(1/4)];
I worry that this will be fairly deceptive about relative values.
J - you're not interested in the imaging method I guess. It's just 6 lines of code lines, starting from your x,y coordinates. Upload your x,y data somewhere if you need more help than my code below.
Hello Walter and Image Analyst,
Walter, thanks for your help, the change you suggested to rgbarray changed the color intensity slightly but the majority of the points are black with a bit more dark blue. I was hoping to get the colors more variable as it is difficult to distinguish between he two.
Image Analyst, thanks for your suggestion, I will try your code and will post later with the results.
All the best
What I think I would suggest at this point is to use interp1() on relative_counts, using a look-up table that emphasized the low values but still had high values. For example,
mapval = interp1( 0:.1:1, [0 .3 .5 .7 .725 .75 .775 .8 .825 .9 1], relative_counts);
rgbarray = [zeros(length(x), 2), mapval(:)];
You would adjust the first parameter (possibly unevenly) according to where you wanted the intensity boundaries to be, and would adjust the second parameter according to the percentage blue you wanted each range to show up with.
John
John on 17 Jan 2013
Edited: John on 17 Jan 2013
Hello Walter,
I tried your new suggestion. Unfortunately the points were all black, similar to the image posted below on Image Analyst's post. When you say 'adjust the first parameter', do mean, 0:.1:1? What would you suggest I change it to? Apologies for all the questions but I don't really understand the code and I'm not sure on how to proceed.
Thank you

Sign in to comment.

If you treat it as an image you could do that, with some work. You could run the thing through a convolution, conv2(). This would give you a higher signal where the roads are more dense. Essentially that is an indexed image. Then you apply a colormap to it, and call ind2rgb to turn it into a color image. Then you use the roads as a mask over the color image so that roads in concentrated areas show up as a different color than roads in sparse areas. Hopefully that described it enough for you to carry out the code. Though I think this representation would be very confusing and distracting to look at.
for k = 1 : length(x)
yourImage(round(y(k)), round(x(k)) = 1;
end
densityImage = conv2(yourImage, ones(5)/25, 'same');
imshow(densityImage, []);
colormap(jet(256));

6 Comments

Hello Image Analyst,
Thank you for your offer to help me with the mapping task.
I was not able to get it to work using your code. This is what I produced using Wlater's code:
I have attached below a blank map and the GPS data used to create this image. I would be grateful if you had the time to explain how your code works.
Regards
J
I couldn't get your links to work, but if you got something working with Walter's code, then just go with it.
Apologies, the files were syncing in my dropbox. They should work now.
If you have the time, I'd like to try your code.
Thanks
Can you upload the image? The fig file is no good to me. But I'm not sure how the x,y would correspond to pixels. I don't have the mapping toolbox so I'd probably have to calibrate the x,y to pixel row,column locations.
Hello Image Analyst,
I am not using the mapping toolbox to source the image. I am using this file on the file exchange to retrieve the map and then I just overlay the data on it. I code I use is below:
latlim = [53.0 53.6];
lonlim = [-6.5 -6];
figure
axis([lonlim, latlim])
axis image
plot_google_map
hold on
plot(x,y,'LineStyle','none','Marker','.','MarkerSize',3);
The x and y data (GPS) is in this file.
Would your method be possible with this setup?
Thank you
An example:
Hello Walter and Image Analyst,
Just wondering if you have had any further thoughts on this?
Thanks

Sign in to comment.

Asked:

on 25 Dec 2012

Community Treasure Hunt

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

Start Hunting!