Adding Annotation boxes on multiple plots in subplot

조회 수: 68(최근 30일)
Christina Reid
Christina Reid 2021년 5월 17일
댓글: Mario Malic 2021년 5월 18일
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
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]
%ff = ff+1;
ss = 1; % subplot
for beta = [1.5,2.5]
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
ylabel ( 'Payload Ratio (lamda_tot)', 'Interpreter', 'none')
xlabel ( 'Dimensionless Ideal Velocity (delta_V/Isp*g_0', 'Interpreter', 'none')
legend( stages, 'Location', 'southwest')
title (' Total payload ratio as a function of demensionless ideal velocity and Number of stages', 'FontSize', 16)


Mario Malic
Mario Malic 2021년 5월 17일
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
Mario Malic
Mario Malic 2021년 5월 18일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by