Coloring scatter plot based on count number

조회 수: 33 (최근 30일)
Butterflyfish
Butterflyfish 2021년 9월 17일
댓글: Butterflyfish 2021년 9월 18일
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!

채택된 답변

Adam Danz
Adam Danz 2021년 9월 17일
편집: Adam Danz 2021년 9월 17일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by