Coloring scatter plot based on count number

19 views (last 30 days)
Hi,
I have a table (results) with time as a first column (result.time) and the count of an event in the second (result.event). I would like to plot the counts through time and colour the dots depending on the count number.
This is the start of my table:
time = ({'25-Jul-2018 00:00:00';'25-Jul-2018 00:15:00';'25-Jul-2018 00:30:00';'25-Jul-2018 00:45:00';'25-Jul-2018 01:00:00';'25-Jul-2018 01:15:00';'25-Jul-2018 01:30:00';'25-Jul-2018 01:45:00';'25-Jul-2018 02:00:00';'25-Jul-2018 02:15:00';'25-Jul-2018 02:30:00';'25-Jul-2018 02:45:00';'25-Jul-2018 03:00:00';'25-Jul-2018 03:15:00';'25-Jul-2018 03:30:00';'25-Jul-2018 03:45:00';'25-Jul-2018 04:00:00';'25-Jul-2018 04:15:00';'25-Jul-2018 04:30:00';'25-Jul-2018 04:45:00'})
time = datetime(time,'InputFormat','dd-MMM-yyyy HH:mm:ss');
event = ([0; 1; 0; 1; 0; 0; 2; 0; 0; 4; 0; 0; 0; 0; 0; 0; 0; 5; 10; 2])
results = table(time,event)
scatter(results.time,results.event)
In the scatter plot, I would like the event markers to be coloured differently depending on their value (e.g. from yellow for small numbers to red for bigger numbers).
Many thanks for your help!

Accepted Answer

Adam Danz
Adam Danz on 17 Sep 2021
Edited: Adam Danz on 17 Sep 2021
Unchanged base code
time = ({'25-Jul-2018 00:00:00';'25-Jul-2018 00:15:00';'25-Jul-2018 00:30:00';'25-Jul-2018 00:45:00';'25-Jul-2018 01:00:00';'25-Jul-2018 01:15:00';'25-Jul-2018 01:30:00';'25-Jul-2018 01:45:00';'25-Jul-2018 02:00:00';'25-Jul-2018 02:15:00';'25-Jul-2018 02:30:00';'25-Jul-2018 02:45:00';'25-Jul-2018 03:00:00';'25-Jul-2018 03:15:00';'25-Jul-2018 03:30:00';'25-Jul-2018 03:45:00';'25-Jul-2018 04:00:00';'25-Jul-2018 04:15:00';'25-Jul-2018 04:30:00';'25-Jul-2018 04:45:00'});
time = datetime(time,'InputFormat','dd-MMM-yyyy HH:mm:ss');
event = ([0; 1; 0; 1; 0; 0; 2; 0; 0; 4; 0; 0; 0; 0; 0; 0; 0; 5; 10; 2]);
results = table(time,event);
Define color
scatter(results.time,results.event, 90, results.event, 'filled')
set colormap
colormap(flipud(autumn(255)))
cb = colorbar();
ylabel(cb, 'Count') % redundant with y-axis

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!