loop plot add text to only one specific plot year
Background:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
endBackground:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
end Background:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
end time series, for loop, text MATLAB Answers — New Questions