Can I add a text annotation to a tiledlayout figure?
118 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Charles Dorchester
am 19 Mai 2022
Beantwortet: David Hill
am 19 Mai 2022
I'm plotting data from different folders onto one plot using a tiledlayout configuration. I'd like to add annotations 'A' through 'H' so that I can refer to individual tiles from the plot in my figure caption.
I'm having trouble getting the functions 'text' or 'annotation' to automatically adjust the location of the annotation to the northwest corner of the tile. Is there a way to easily do this, similar to how legend will automatically place the legend in each individual tile through a function call like "legend('blah blah', 'Location','Northwest')"?
Below is my code, where calling the text function like "text(0.03,0.005,subPlotNames(i))" would require manually adjusting the x,y coordinates of the function call and is not flexible if number of tiles are adjusted.
subPlotNames = ["A","B","C","D","E","F","G","H"];
fig = figure(1)
for i = 1:8
cd(ffolders(i))
load plotting_mat_adv.mat
i
t=subplot(2,4,i)
h(:,1) = plot(fluid_conductivity2_adv(1:injection-1,1),...
conductivity_bulk2(1:injection-1,1),'r--x') % injection
hold on
h(:,2) = plot(fluid_conductivity2_adv(flush-1:end,1),...
conductivity_bulk2(flush-1:end,1),'b--x') % flush
% the following line does not work
text(subPlotNames(i),'Location','Northwest')
% something like text(0.03,0.005,subPlotNames(i)) would require
% manually adjusting the x,y coordinates of the function call and is
% not flexible if number of tiles are adjusted.
ylim([0.005 .035]), xlim([0.005, 0.02])
set(gca,'FontSize',12,'FontName','Calibri');
if i == 1 || i == 5
;
else
set(gca,'ytick',[])
end
end
Below is a visual of what I'd like to achieve, where A would proceed to B, C, etc for each tile.
0 Kommentare
Akzeptierte Antwort
David Hill
am 19 Mai 2022
subPlotNames = 'ABCDEFGH';
fig = figure(1);
hold on;
set(gca,'FontSize',12,'FontName','Calibri');
for i = 1:8
x=randi(randi(100)+20,1,10);
y=randi(randi(30)+10,1,10);
subplot(2,4,i)
plot(x,y);
x=randi(100,1,10);
y=randi(30,1,10);
plot(x,y);
xlim(xlim+[-10,10]);ylim(ylim+[-10,10]);%use xlim and ylim to fix location
text(min(xlim), max(ylim),subPlotNames(i), 'Horiz','left', 'Vert','top')
end
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!