Add annotation to a parent figure middle left

2 次查看(过去 30 天)
I am using code below to creat a n*1 plot:
figure1 = figure('PaperSize',[8 8]);
for i=1:N
f = subplot(N,1,i);
plot(X,Y, 'Color','k');
end
I would like to add an annotation/text to the center left of the figure, vertically.
I am using the following code to do so:
xlim = get(gca,'XLim');
ylim=get(gca,'YLim');
ht = text(xlim(1)+0.95*xlim(2),0.5*ylim(1)+0.5*ylim(2),'Absorbance [a.u.]');
set(ht,'Rotation',90);
However, the gca is getting the xlim and ylim of the last subplot, not the whole figure. Any suggestion to do so?
Following is what I want to achieve.

采纳的回答

Srivardhan Gadila
Srivardhan Gadila 2020-5-28
The following code might help you:
close all
figure1 = figure('PaperSize',[8 8]);
N = 5;
for i=1:N
f = subplot(N,1,i);
plot(rand(10,1))
% plot(X,Y, 'Color','k');
end
ax = subplot(N,1,round(N/2))
ht = text(ax,0,mean(ax.YLim),'Absorbance [a.u.]','HorizontalAlignment','center');
set(ht,'Rotation',90);
  2 个评论
Zhen Liu
Zhen Liu 2020-5-30
Thanks for your answer. It works perfectly if I don't reverse the X-axis. But if I reverse the X direction, the text does not show up. Anything I should modify from the code?
The following is the code I used:
figure1 = figure('PaperSize',[8 8]);
for i=1:N
f = subplot(N,1,i);
Y = Table.(i+1);
plot(X,Y, 'Color','k');
set(gca,'XDir','reverse');
Name = Table.Properties.VariableNames{i+1};
legend(Name,'Location','Northwest','Interpreter','none');
legend boxoff;
end
ax = subplot(N,1,round(N/2))
ht = text(ax,0,mean(ax.YLim), 'Absorbance [a.u.]', 'HorizontalAlignment','center');
set(ht,'Rotation',90);
Thank you.
Zhen Liu
Zhen Liu 2020-5-30
I adjusted the code :
ht = text(ax,0,mean(ax.YLim), 'Absorbance [a.u.]', 'HorizontalAlignment','center');
make it
ht = text(ax,2*mean(ax.XLim),mean(ax.YLim), 'Absorbance [a.u.]', 'HorizontalAlignment','center');
And it is workign now. Thanks again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by