Best way to get constant plot sizes with varying width Yticklabels?

4 次查看(过去 30 天)
  • Matlab 2021a
  • Windows 10 64-bit
I am using the awesome exportgraphics command after programmatically fixing the size of the plot window to save the figures as vector PDFs. I then use these PDFs as figures in a LaTeX document with identical scaling parameters.
My issue is that width of the yticklabels scales the innerposition of the plot so that importing a figure with only two digit widths on the yticklablels next to one with three digits results in different sized plots. This effect is much worse if one of them contains a negative sign.
In other words, the entire bounding box (I believe is called the outerposition) of the figure is fixed size. But because the width of the yticklabels changes, the actual plot window scales to fit.
I have not tried it yet, but I believe that changing the fixed size of the plot window (innerposition) results in PDFs of different sizes, which will have the same result once it is added to the Latex document. I do not want to have custom scaling for each figure.
  2 个评论
Jan
Jan 2021-4-17
It would be useful if you post a small working example with the creation of two axes. Then we need to know, which "awsome exportfigure" command you mean. Why not using printf -eps or the famous export_fig?
William Perdikakis
William Perdikakis 2021-4-17
编辑:William Perdikakis 2021-4-17
Sorry, I meant exportgraphics, corrected above.
This should be a MWE of the issue. Be sure to open the PDFs in the same sized window.
From this example, you can clearly see that one PDF is wider than the other. If these figures are scaled into the same sized bounding box the one labeled "small" will scale down more and appear smaller.
A solution that I can think of would be forcing the ylabeltick width, so the 'normal' graph would have padding on the left side, for example.
N=100;
t=linspace(0,2*pi,N);
y=sin(t);
plot(t,y+1)
ylabel('normal')
exportgraphics(gca,'normal.pdf','ContentType','vector')
figure
plot(t,100*y)
ylabel('small')
exportgraphics(gca,'small.pdf','ContentType','vector')

请先登录,再进行评论。

回答(1 个)

Rishik Ramena
Rishik Ramena 2021-5-24
The plot sizes rendered by the exportgraphics function for vectors will be the same, but the dimensions of the pdf file will depend on your x and y labels and values. You can consider setting the labels and tick sizes in the plots but even that would not guarantee a consistent pdf size. I would suggest you to try the export_fig function. Try the -nocrop option, it might serve your purpose. Here's a link to the github page with usages and examples.

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by