필터 지우기
필터 지우기

Can I add a text annotation to a tiledlayout figure?

조회 수: 118 (최근 30일)
Charles Dorchester
Charles Dorchester 2022년 5월 19일
답변: David Hill 2022년 5월 19일
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.

채택된 답변

David Hill
David Hill 2022년 5월 19일
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

추가 답변 (1개)

David Hill
David Hill 2022년 5월 19일
Look at text function
  댓글 수: 1
Charles Dorchester
Charles Dorchester 2022년 5월 19일
I have. And my approach to this is explained in the post.
The issue I'm running into: "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".
Do you know if it is possible (and if so, how to do it) to have the location of the text annotation automatically defined in relation to the tile? The current way sets the text annotation location relative to the entire figure

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by