# Adding Annotation boxes on multiple plots in subplot

2 views (last 30 days)
Christina Reid on 17 May 2021
Commented: Mario Malic on 18 May 2021
I have a script where I am trying to evaluate plots with two constants and 1 variable. I believe the plots are correct and now I would like to display an annotation box that displays the variables so I know which plot represents what. I try to do this in line 32, but the annotation box only shows up on the first subplot. Instead
%% Coursework Number 1.2:
% Basing on the "Ideal Rocket Flight Performance" theory compute and show
% through suitable curves the optimal (maximum) total payload ratio
% lamda_tot of a multisage rocket with identical stages (c_i = c, k_ti =
% k_t, (T/W)_i = (T/W), and a0_i = a0) ) as a function of the number of stages N.
% delta_V/c equal to 0.5, 1.0, 2.0, 3.0, and 4.0
%k_t equal to 0.1, 0.075 and 0.095
clear all
figure
x = [ 0.5, 1.0, 2.0, 3.0, 4.0];
delta_V = x; % deltaV/c
line_color = ['b' 'g' 'y' 'c' 'm'];
stages = cell(1, length(line_color));
%n = 1:5;
kt = 0.075;
ff = 1; % figure
for TW = [50]
figure(ff)
%ff = ff+1;
ss = 1; % subplot
for beta = [1.5,2.5]
subplot(2,1,ss)
ss=ss+1;
for nn = 1: length(line_color);
ke = beta / TW;
lamda_totmax = (((1+kt)*exp(-delta_V./nn))-kt-ke).^nn;
stages{nn} = sprintf('%d Stage(s)' ,nn);
annotation('textbox',[.2 .5 .3 .3],'String',['T/W = ' int2str(TW), ' Kt = ' num2str(kt), ' beta = ' num2str(beta)], 'FitBoxToText', 'on')
semilogy(x, lamda_totmax, '-', 'Color', line_color(nn), 'LineWidth', 2)
grid on
hold on
end
ylabel ( 'Payload Ratio (lamda_tot)', 'Interpreter', 'none')
xlabel ( 'Dimensionless Ideal Velocity (delta_V/Isp*g_0', 'Interpreter', 'none')
legend( stages, 'Location', 'southwest')
end
end
title (' Total payload ratio as a function of demensionless ideal velocity and Number of stages', 'FontSize', 16)

Mario Malic on 17 May 2021
Hi,
If you zoom in the picture, you'll see that text is plotted one over another. It happens because parent container is figure, not axes as you expected. Different position arguments for each annotate function and you'll solve it (probably you did already).
##### 2 CommentsShowHide 1 older comment
Mario Malic on 18 May 2021
Second argument is y coordinate, your beta is a two
annotation('textbox',[.2 .2 .3 .3],'String',['T/W = ' int2str(TW), ' Kt = ' num2str(kt), ' beta = ' num2str(beta)], 'FitBoxToText', 'on')
% ^ This argument
The second element changes the y position of annotation, however, I can only tell that it has weird behaviour so try it out first on some figure with subplots.