Scatter plot with graduated marker colours
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (2)
Kye Taylor
am 18 Dez. 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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Purple finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!