for loop which changes color depending on the month
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to write a for loop where each month on my graph is a different colour. I am very unfamiliar with for loop and im unsure on how i work it into the code. I want the first subplot to have a rainbow essentially. Here is what I currently have.
c=hsv(12);
plotIndex = month(windTurbineData.disc_TimeStamp);
meancapacity = windTurbineData.mean_Power_kW/7000
colormap(c)
for i = 1:12
subplot (2,2,[1,2]);
plot(windTurbineData.disc_TimeStamp,meancapacity)
title('Power Output 2019')
ylabel('Power output/rated power [-]')
ylim([-0.2 1.2])
grid on
end
subplot (2,2,3);
title('Power Output vs Wind Speed 2019')
xlabel('Wind Speed m/s')
ylabel('Power output/rated power [-]')
colorbar
subplot(2,2,4);
title('Standard Deviation in Power Output 2019')
xlabel('Wind Speed m/s')
ylabel('Std Power output/rated power [-]')
colorbar('Ticks', linspace(0, 1, 12), 'TickLabels',{'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'})
0 Commenti
Risposte (1)
DGM
il 30 Nov 2021
Modificato: DGM
il 2 Dic 2021
I don't have your data, so I just have to assume some placeholder data instead.
It's probably better to use a legend for identifying line plots like this. If you want to actually use a colorbar, you'll need to correctly configure it so that the labels line up with the discrete color segments, otherwise it's ambiguous.
Depending on what your actual data looks like, overlaying that many line plots might end up being pretty hard to read anyway.
monthnames = {'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'};
% placeholder data
t = datenum([2000 2000],[01 12],[01 31]);
t = t(1):t(2);
P = rand(1,numel(t));
S = P + 0.05*randn(1,numel(t));
% normalized power per month
plotIndex = month(t);
meancapacity = P;
subplot (2,2,[1,2]);
hold on
for moy = 1:12
mask = plotIndex==moy;
plot(day(t(mask)),meancapacity(mask))
end
title('Power Output 2019')
ylabel('Power output/rated power [-]')
xlabel('Day of Month')
ylim([-0.2 1.2])
grid on
set(gca,'colororder',hsv(12));
legend(get(gca,'children'),monthnames,'location','eastoutside');
% power vs speed
[Ssorted idx] = sort(S);
Psorted = P(idx);
subplot (2,2,3);
plot(Ssorted,Psorted);
title('Power Output vs Wind Speed 2019')
xlabel('Wind Speed m/s')
ylabel('Power output/rated power [-]')
% std per month
Pstd = zeros(1,12);
for moy = 1:12
mask = plotIndex==moy;
Pstd(moy) = std(P(mask));
end
subplot(2,2,4);
plot(1:12,Pstd)
title('Standard Deviation in Power Output 2019')
ylabel('Std Power output/rated power [-]')
set(gca,'xtick',1:12,'xticklabels',monthnames,'xticklabelrotation',90)
The titles and labels all collide here on the web display, but should be better if the figure is allowed to be larger.
EDIT:
Related question that should be closer to the goals.
0 Commenti
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!