Creating a plot that changes colour as the month changes

2 visualizaciones (últimos 30 días)
Sebastian Sunny
Sebastian Sunny el 1 de Dic. de 2021
Editada: Stephen23 el 10 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, the data that is provided already has time stamp values.
  1 comentario
Stephen23
Stephen23 el 10 de Dic. de 2021
Editada: Stephen23 el 10 de Dic. de 2021
Original question by Sebastion Sunny retrieved from Google Cache:
Creating a plot that changes colour as the month changes
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, the data that is provided already has time stamp values. Also, the problem requires me to use the month and a for loop functions.I have attached the data below and the code here:
stdofpowerratedpower = (windTurbineData.std_Power_kW)/(7000);
PowerOutputRatingPower = (windTurbineData.mean_Power_kW)/(7000);
c = hsv(12);
for = 1:12
subplot (2,2,[1 2])
plot(timeData,PowerOutputRatingPower);% plotting mean,max,min of Power
ylim([-0.2,1.2]);
title('Power Output 2019')
ylabel('Poweroutput/rated power [-]')
end
subplot (2,2,3)
plot(windTurbineData.mean_WindSpeed_mps,PowerOutputRatingPower,'.')
xlabel('Windspeed m/s')
ylabel('Power output/ rated power')
ylim([-0.2 1.2])
colorbar('Ticks',linspace(0,1,12),'TickLabels',{'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'})
set(gca,'Colormap',c)
subplot (2,2,4)
plot(windTurbineData.mean_WindSpeed_mps,stdofpowerratedpower,'.')
xlabel('Windspeed 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'})
set(gca,'Colormap',c)
Thank you

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 2 de Dic. de 2021
Editada: DGM el 2 de Dic. de 2021
I answered a very similar question yesterday, iirc.
In that, I recommended to use a legend (and that's what I show in the example), but in the answer to your prior question, I provide an example of using a colorbar as a legend.
Since I see that the PDF you're using shows the use of a colorbar, you could certainly just use the colorbar example from earlier today with the plot setup in the link above. That uses both month() and a set of loops to deal with data grouping. I'm only using placeholder data, so you'll have to adjust things as needed.
EDIT:
monthnames = {'Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec'};
cmap = hsv(12);
% placeholder data
t = datenum([2000 2000],[01 12],[01 31]);
t = t(1):t(2);
meancapacity = rand(1,numel(t));
speed = meancapacity + 0.05*randn(1,numel(t));
% normalized power per month
plotIndex = month(t);
for moy = 1:12
% split by month
mask = plotIndex==moy;
thist = t(mask);
thismeancap = meancapacity(mask);
thisspeed = speed(mask);
% main power plot
subplot(2,2,[1,2]); hold on
plot(thist,thismeancap)
% power vs speed
subplot(2,2,3); hold on
plot(thisspeed,thismeancap,'.');
% std vs speed
subplot(2,2,4); hold on
% placeholder; idk what this means
plot(thisspeed,thismeancap,'.');
end
subplot(2,2,[1,2])
datetick('x',3)
title('Power Output 2019')
ylabel('Power output/rated power [-]')
xlabel('Month 2019')
ylim([-0.2 1.2])
grid on
set(gca,'colororder',cmap);
subplot(2,2,3);
title('Power Output vs Wind Speed 2019')
xlabel('Wind Speed m/s')
ylabel('Power output/rated power [-]')
colormap(cmap)
cb = colorbar;
cb.Ticks = 1/24:1/12:1;
cb.TickLabels = monthnames;
subplot(2,2,4);
title('Standard Deviation in Power Output 2019')
xlabel('Wind Speed m/s')
ylabel('Std Power output/rated power [-]')
colormap(cmap)
cb = colorbar;
cb.Ticks = 1/24:1/12:1;
cb.TickLabels = monthnames;
The third plot section isn't complete, since I don't understand what exactly is supposed to be plotted. It asks for "the standard deviation as a fraction of the rated power against wind speed". The standard deviation of a vector is a scalar. The rated power is a scalar. The ratio of scalars is a scalar. The plot of a scalar versus a vector is a horizontal line.

Más respuestas (1)

Walter Roberson
Walter Roberson el 2 de Dic. de 2021

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by