Scatter plot with graduated marker colours

8 views (last 30 days)
Jo
Jo on 18 Dec 2012
I would like to plot a simple scatter graph, with marker colours varying from one end of the spectrum to the other (e.g. red, orange, yellow....blue, purple).
My data compares the amount of water in a river with the quality of the water, over time (3 simple columns: time, amount, quality). I would like to plot the x,y scatter plot of amount vs quality, but with the colour progressing over time, so that it is possible to see the progression of the quality over time.
I will need to produce many graphs of this type, so if I can find a piece of code that will work for any length of dataset, that would be really useful.
Many thanks in advance for helping a Matlab novice!

Answers (2)

Kye Taylor
Kye Taylor on 18 Dec 2012
I wrote a function that is used in the following code as one way to accomplish what you're looking for. Download that function (called buildcmap.m) here
% Create a toy dataset to represent yours
N = 100; % number of points
time = sort(rand(N,1)); % assumes time is monotonically increasing
quality = rand(N,1);
% Since you are plotting amt vs quality (y vs x), the following sort of
% represnts amt being a linear function of quality + noise.
amt = quality + .1*randn(N,1);
data = [time,amt,quality];
% see comments in buildcmap
cmap = buildcmap(data(:,1));
scatter(data(:,3),data(:,2),[],cmap)
% Uncomment the following lines and run it to confirm that buildcmap is
% creating a colormap based on its vector input.
% cmap2 = buildcmap(data(:,2));
% scatter(data(:,3),data(:,2),[],cmap2)

Jo
Jo on 18 Dec 2012
Thank you! I'll give it a go!

Community Treasure Hunt

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

Start Hunting!