How to adjust the position of a text on a plot?
    17 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Wiqas Ahmad
 le 27 Juil 2021
  
    
    
    
    
    Réponse apportée : Cris LaPierre
    
      
 le 27 Juil 2021
            I want to adjust the postion of the text S0=(1,1,0,0) and to put each in fron of a,b and c in the subplots. I also want to redue the space between the subplots denoted 1 and 2 enclosed by red rectangles. How can I do it? My program and figure can be seen:
clc;
clear all;
close all;
%% ------------------------------Program-------------------------------------
N0=100;
r_med=[0.445 0.889 1.445 2];
sigma_g=7;
N_ang=9001;
theta=0:0.01:180;
col=['k' 'b' 'r' 'g'];
for i=1:length(r_med)
    [P11(i,:),P12(i,:),P33(i,:),P34(i,:),~,~,~] = ZK_W_Cloud_PhaseFunc(N0,r_med(i),sigma_g,N_ang)
    f1(i,:)=((P11(i,:)-P12(i,:))./2);
    f2(i,:)=((P11(i,:)+P12(i,:))./2);
    f3(i,:)=P33(i,:)/2;
    %numer(i,:)=0.125*((f2(i,:).*(cosd(theta)).^2)+f1(i,:)-(2.*(f3(i,:).*cosd(theta))));
    denomin(i,:)=0.125*((3.*(f2(i,:).*(cosd(theta)).^2))+(3.*f1(i,:))+(2.*(f3(i,:).*cosd(theta))));
    %ldpr(i,:)=smooth((numer(i,:)./denomin(i,:)));%Linear depolarization ratio
    figure(1)
    hold on
    subplot(1,3,1);
    plot(theta,denomin(i,:),'color',col(i),'LineWidth',2);
    xlabel('\fontname{Arial}Scattering angle \theta(\circ)','FontSize',14,'FontWeight','normal');
    ylabel('\fontname{Arial}Phase function P_{L\mid\mid}(\theta)(sr^-^1)','FontSize',14,'FontWeight','normal');
    set(gca,'yscale','log');
    yMin = floor(min(denomin(i,:)));
    yMax = ceil(max(denomin(i,:)));
    set(gca,'xlim',[0 60],'xtick',[0:20:60],'ylim',[1e-2 1e4],'ytick',10.^(-2:2:4));
    set(gca,'color','w','Fontsize',12,'LineWidth',1,'Fontweight','normal');
    set(gca,'box','off','Fontname','Arial','Fontsmoothing','on');
    set(gca,'xgrid','on','ygrid','on','gridcolor','k');
    legend('R_{eff}= 4\mum','R_{eff}= 8\mum','R_{eff}= 13\mum','R_{eff}= 18\mum','location','Northeast');% we need to calculate Reff from Rm using formaula
    legend boxoff
    caption = sprintf('S_{0}=(1,1,0,0)');
    dim = [0.4 .49 .2 .42];%[left bottom width height]
    annotation('textbox',dim,'String',caption,'FitBoxToText','on','FontSize',14,'FontWeight','normal','FontName',...
        'Arial','EdgeColor','w');
    nIDs = 1;
    alphabet = ('a':'z').';
    chars = num2cell(alphabet(1:nIDs));
    chars = chars.';
    charlbl = strcat('(',chars,')'); % {'(a)','(b)','(c)','(d)'}
    text(0.03,0.95,charlbl{1},'Units','normalized','FontSize',14)
    %figure(2)
    hold on
    subplot(1,3,2);
    plot(theta,denomin(i,:),'color',col(i),'LineWidth',2);
    xlabel('\fontname{Arial}Scattering angle \theta(\circ)','FontSize',14,'FontWeight','normal');
    %ylabel('\fontname{Arial}Phase function P_{L\mid\mid}(\theta)(sr^-^1)','FontSize',14,'FontWeight','normal');
    set(gca,'yscale','log');
    yMin = floor(min(denomin(i,:)));
    yMax = ceil(max(denomin(i,:)));
    set(gca,'xlim',[60 120],'xtick',[60:20:120],'ylim',[1e-4 1e-1],'ytick',10.^(-4:1:-1));
    set(gca,'color','w','Fontsize',12,'LineWidth',1,'Fontweight','normal');
    set(gca,'box','off','Fontname','Arial','Fontsmoothing','on');
    set(gca,'xgrid','on','ygrid','on','gridcolor','k');
    legend('R_{eff}= 4\mum','R_{eff}= 8\mum','R_{eff}= 13\mum','R_{eff}= 18\mum','location','Northeast');% we need to calculate Reff from Rm using formaula
    legend boxoff
    caption = sprintf('S_{0}=(1,1,0,0)');
    dim = [.2 .49 .2 .42];%[left bottom width height]
    annotation('textbox',dim,'String',caption,'FitBoxToText','on','FontSize',14,'FontWeight','normal','FontName',...
        'Arial','EdgeColor','w');
    nIDs = 2;
    alphabet = ('a':'z').';
    chars = num2cell(alphabet(1:nIDs));
    chars = chars.';
    charlbl = strcat('(',chars,')'); % {'(a)','(b)','(c)','(d)'}
    text(0.03,0.95,charlbl{2},'Units','normalized','FontSize',14)
    %figure(3)
    hold on
    subplot(1,3,3);
    plot(theta,denomin(i,:),'color',col(i),'LineWidth',2);
    xlabel('\fontname{Arial}Scattering angle \theta(\circ)','FontSize',14,'FontWeight','normal');
    %ylabel('\fontname{Arial}Phase function P_{L\mid\mid}(\theta)(sr^-^1)','FontSize',14,'FontWeight','normal');
    set(gca,'yscale','log');
    yMin = floor(min(denomin(i,:)));
    yMax = ceil(max(denomin(i,:)));
    set(gca,'xlim',[120 180],'xtick',[120:20:180],'ylim',[1e-4 1e-1],'ytick',10.^(-4:1:-1));
    set(gca,'color','w','Fontsize',12,'LineWidth',1,'Fontweight','normal');
    set(gca,'box','off','Fontname','Arial','Fontsmoothing','on');
    set(gca,'xgrid','on','ygrid','on','gridcolor','k');
    legend('R_{eff}= 4\mum','R_{eff}= 8\mum','R_{eff}= 13\mum','R_{eff}= 18\mum','location','Northeast');% we need to calculate Reff from Rm using formaula
    legend boxoff
    caption = sprintf('S_{0}=(1,1,0,0)');
    dim = [.1 .49 .2 .42];%[left bottom width height]
    annotation('textbox',dim,'String',caption,'FitBoxToText','on','FontSize',14,'FontWeight','normal','FontName',...
        'Arial','EdgeColor','w');
    nIDs = 3;
    alphabet = ('a':'z').';
    chars = num2cell(alphabet(1:nIDs));
    chars = chars.';
    charlbl = strcat('(',chars,')'); % {'(a)','(b)','(c)','(d)'}
    text(0.05,0.95,charlbl{3},'Units','normalized','FontSize',14)
    % Enlarge figure to full screen.
    set(gcf, 'units','normalized','outerposition',[.1 .4 .8 .5]);
end

0 commentaires
Réponse acceptée
  Cris LaPierre
    
      
 le 27 Juil 2021
        For your subplot spacing, try using tilelayout instead. It has optional inputs for TileSpacing and Padding.
t = tiledlayout(1,3,'TileSpacing','Compact','Padding','Compact');
0 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Subplots dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

