Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a scatter plot with graduated marker colours in MATLAB?

I would like to plot a simple scatter graph in MATLAB, 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!

like image 477
user1913275 Avatar asked Dec 18 '12 15:12

user1913275


People also ask

How do you add a marker to a plot in MATLAB?

Add markers in one of these ways: Include a marker symbol in the line-specification input argument, such as plot(x,y,'-s') . Specify the Marker property as a name-value pair, such as plot(x,y,'Marker','s') .

How do you fill a marker color in MATLAB?

Fill the markers with a shade of orange by setting the MarkerFaceColor property on the Line object. Then increase the marker size to 8 by setting the MarkerSize property. Change the outlines of the markers to match the fill color by setting the MarkerEdgeColor property.

How do you add color to a scatter plot?

To edit the colours, select the chart -> Format -> Select Series A from the drop down on top left. In the format pane, select the fill and border colours for the marker.

How do I change the color of a scatter plot in MATLAB?

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red" .


1 Answers

You can use the color argument of scatter

If your data are already sorted in time than simply use:

% let n be the number of points you have
cmp = jet(n); % create the color maps changed as in jet color map
scatter(x, y, 10, cmp, 'filled');

Otherwise you need to sort your data first:

[time, idx] = sort(time);
x = x(idx);
y = y(idx);
cmp = jet(n); % create the color maps changed as in jet color map
scatter(x, y, 10, cmp, 'filled');
like image 118
Shai Avatar answered Nov 15 '22 07:11

Shai