Splitting a Colorbar into 12 parts according to months from data
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sebastian Sunny
el 1 de Dic. de 2021
Comentada: DGM
el 2 de Dic. de 2021
Hi,
Im trying to use the month function and a for-loop to find and plot specific data according to different months, for example january would be red and february would be blue. I have been trying to have 12 different colors for each month corresponding to each data set.
Thank you
2 comentarios
Walter Roberson
el 2 de Dic. de 2021
What is the difference between this and https://www.mathworks.com/matlabcentral/answers/1600850-splitting-a-colorbar-into-12-parts-according-to-months-from-data?s_tid=srchtitle ?
DGM
el 2 de Dic. de 2021
I think this question and answer are at least general enough to be useful to future searches.
Respuesta aceptada
DGM
el 1 de Dic. de 2021
If you're doing a line plot, it may make more sense to just use a legend.
% the selected colormap
cmap = jet(12);
% dummy data
x = 1:30;
y = rand(12,30)+(1:12).';
% plot setup
hp = plot(x,y);
set(gca,'colororder',cmap)
monthnames = {'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'};
legend(hp,monthnames);
If you really want to use a discrete colorbar that way instead, you can.
clf;
% the selected colormap
cmap = jet(12);
% dummy data
x = 1:30;
y = rand(12,30)+(1:12).';
% plot setup
plot(x,y)
set(gca,'colororder',cmap)
% wrangle the discrete colorbar tick alignment
colormap(cmap)
cb = colorbar;
cb.Ticks = 1/24:1/12:1;
monthnames = {'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'};
cb.TickLabels = monthnames;
Más respuestas (0)
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!