exportgraphics: adding a margin

195 ビュー (過去 30 日間)
dormant
dormant 2021 年 6 月 21 日
コメント済み: Alexander Moody 2023 年 8 月 28 日
Is it possible to add a margin to figures saved using the exportgraphics function?
It crops a tad too tightly for my needs.

回答 (2 件)

Paul Wintz
Paul Wintz 2021 年 9 月 15 日
編集済み: Paul Wintz 2021 年 11 月 18 日
You can force exportgraphics to export the entire figure by drawing an white rectange around it with the command
annotation('rectangle',[0 0 1 1],'Color','w');
To adjust the margins, change the dimensions [0 0 1 1].
As noted by @David Walwark in the comments, the plot will not be interactive while it is annotated. To restore interactivity, delete the annotation after calling exportgraphics.
a = annotation('rectangle',[0 0 1 1],'Color','w');
% -> Save figure here <-
delete(a)
  4 件のコメント
Bill Tubbs
Bill Tubbs 2023 年 3 月 23 日
編集済み: Bill Tubbs 2023 年 3 月 23 日
This didn't work for me. Presumably when doing 2 subplots you need to apply this annotation to each subplot?
I tried adjusting the margins to [-0.05 -0.05 1.05 1.05] and it raises:
Error using annotation (line 116)
Position values must be between 0 and 1.
Alexander Moody
Alexander Moody 2023 年 8 月 28 日
Had the same issue... this worked for me, but I had to change the color of the annotation rectangle to something other than white for it to work.

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


Kiran Felix Robert
Kiran Felix Robert 2021 年 6 月 24 日
Hi Dormant,
If you are trying to export multiple sub-images/plots onto a single figure, you can explore the tiledlayout to introduce spacing using the 'TileSpacing' Name-Value pair.
  2 件のコメント
Paul Wintz
Paul Wintz 2021 年 9 月 15 日
This doesn't answer the question. How do we adjust the margins on the outside of a figure saved with exportgraphics?
Bill Tubbs
Bill Tubbs 2023 年 3 月 23 日
This worked for me. When I did my 2-plot figure using tiledlayout instead of subplots the outer margin was significantly wider.

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

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by