How to plot multiple year data over common months?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JMSE
el 5 de En. de 2022
Comentada: JMSE
el 6 de En. de 2022
Dear all,
how to plot data from multiple years over one common x-axis? I have some test data measured in january over 4 years, and I want to color the data corresponding the different years. This testdata (datetime data & measurement data) containts data for January only, however future measurements may contain other months, too. So I would like to have x.axis ticks 1-12 (months) and user a scatterplot(?) to mark the points corresponding to n years (colormarker). Please find the test data attached and many thanks for help in advance!
dt=readtable("Test.xlsx");
plot (dt.Date, dt.NO2,"r.")
1 comentario
Star Strider
el 5 de En. de 2022
Please provide more data. There is only one month (January) for all four years in that file excerpt.
Respuesta aceptada
Walter Roberson
el 5 de En. de 2022
With different markers as well as different colors (different colors alone is easier.)
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/853865/Test.xlsx';
dt = readtable(filename);
[y, m, d] = ymd(dt.Date);
baseyear = min(y);
lastyear = max(y);
cmap = colormap(jet(lastyear-baseyear+1));
G = y - baseyear + 1;
x = datetime(baseyear, m, 1, 'Format', 'MM');
pointsize = 30;
markers = {'.', '+', '*', '<', 'o', 's'}.';
assert(length(markers) >= max(G), 'Need more markers');
markermap = markers(G);
hold on
splitapply(@(M,NO2,c,mark) scatter(M, NO2, pointsize, c(1,:), mark{1}), x, dt.NO2, cmap(G,:), markermap, G);
%scatter(x, dt.NO2, pointsize, cmap(y-baseyear+1,:));
hold off
xlim auto; ylim auto;
ax = gca; ax.XRuler.TickLabelFormat = 'MMM';
xticks(datetime(baseyear,1:12,1))
8 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!