Coloring scatter plot based on count number
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Butterflyfish
le 17 Sep 2021
Commenté : Butterflyfish
le 18 Sep 2021
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).
I have found some interesting ideas there: https://in.mathworks.com/matlabcentral/answers/28849-coloring-scatterplots-based-on-frequency-of-point-occurrence-in-input but it is not exactly what I need.
Many thanks for your help!
0 commentaires
Réponse acceptée
Adam Danz
le 17 Sep 2021
Modifié(e) : Adam Danz
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Orange dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!