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!
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') .
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.
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.
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" .
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With