How do you add a header to a printed figure?

31 ビュー (過去 30 日間)
Carl Hopkins
Carl Hopkins 2017 年 5 月 23 日
回答済み: Sean de Wolski 2021 年 5 月 14 日
Suppose you wanted to write a script to make several pages of figures each with several small subplots that could be used as thumbnails. When done, you would like to print the figures each with a header containing the page number and the number of pages of similar plots. For example:
for page = 1:3
figure (page)
clf
for sub = 1:9
subplot(3,3,sub)
plot(1:100,rand(1,100))
end
set(gcf,'PaperPosition',[.25 .25 8 10])
% add page header here
end
and you want to put a header on the page like this
  3 件のコメント
Carl Hopkins
Carl Hopkins 2021 年 5 月 14 日
Thank you Grzegorz Lippe:
This addition to Matlab sgtitle() is exactly the solution needed for this problem. A page of subplots needs to have its own title and this works seamlessly. Jan's answer has served as solution for the time being but this new function is perfect.
Adam Danz
Adam Danz 2021 年 5 月 14 日
If you're using tiledlaytout (Matlab R2019b and later), you can assign the title to the tiledlayout object.
figure
tlo = tiledlayout(3,3);
nexttile; nexttile; nexttile;
nexttile; nexttile; nexttile;
nexttile; nexttile; nexttile;
title(tlo, 'Global Title', 'FontWeight','Bold','FontSize',18)

サインインしてコメントする。

採用された回答

Carl Hopkins
Carl Hopkins 2021 年 5 月 14 日
see above for sbtitle()

その他の回答 (3 件)

Jan
Jan 2017 年 5 月 23 日
Add a text to an invisible axes covering the complete figure:
AxesH = axes('Units', 'Normalized', 'Position', [0,0,1,1], 'Visisble', 'off', ...
'NextPlot', 'add');
text(0.5, 0.99, 'Your figure title', 'Parent', AxesH, ...
'Units', 'normalized', ...
'VerticalAlignment', 'top', 'HorizontalAlignment', 'center');
  1 件のコメント
Carl Hopkins
Carl Hopkins 2017 年 5 月 23 日
Brilliant ! Thank you very much.
AxesH = axes('Units', 'Normalized', 'Position', [0,0,1,1], 'Visible', 'off', ...
'NextPlot', 'add');
text(0.5, 0.99, 'Your figure title', 'Parent', AxesH, ...
'Units', 'normalized', ...
'VerticalAlignment', 'top', 'HorizontalAlignment', 'center');

サインインしてコメントする。


KL
KL 2017 年 5 月 23 日
title(['Pg.no:' num2str(page) ' sub:' num2str(sub)])
add this next to plot
  1 件のコメント
Carl Hopkins
Carl Hopkins 2017 年 5 月 23 日
Thank you for your response. Although title works well for labeling an individual axis, but it does not put a header on a page with multiple axes. I would like to have a header or footer on the page that numbers the pages of plots in sequence (as in the figure where I did it manually)

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2021 年 5 月 14 日
You can use the MATLAB Report Generator to build sophisticated reports with whatever formatting, chapters, sections, etc. you need. A trivial example:
import mlreportgen.report.*
import mlreportgen.dom.*
r = Report('figs', 'pdf');
t = Text("Figures:");
t.Style = {Bold, FontSize('24pt')};
add(r, t);
for ii = 1:3
plot(sin(1:(2^(ii+1))))
add(r, Figure);
end
close(r)
% rptview(r)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by