Size of the legend versus paper size
3 views (last 30 days)
Show older comments
Sylvain Chevillard
on 16 Jan 2020
Commented: Raunak Gupta
on 30 Jan 2020
The following code attempts to produce three PDF of the same figure, with three different paper sizes. I would like, and it should be possible, to get more or less the same PDF except that it is scaled to the desired size. I mostly achieve this goal, except for the legend, whose rendering differs depending on the paper size in a way that seems uncontrolable to me. Especially, I did not achieve to use leg.Position to make the legend look the same in all three pdf files. Am I missing something? Or should it be considered as a bug?
x = linspace(0, pi, 100);
fig = figure;
curve = plot(x,sin(x));
ax = fig.CurrentAxes;
fig.Units = 'pixels';
fig.Position = [1 1 560 420];
ax.Units = 'pixels';
ax.Position = [28 21 504 378];
leg = legend('sin(x)');
for paperwidth = [8 12 50]
% Scale the font size and line widths with the paperwidth
ax.FontSize = 0.7 * paperwidth;
ax.LineWidth = 0.05 * paperwidth;
curve.LineWidth = 0.15 * paperwidth;
leg.FontSize = 0.7 * paperwidth;
% Sets the paper size to match the geometry of the figure
% with a a given width.
fig.PaperUnits = 'centimeters';
paperheight = paperwidth * fig.Position(4)/fig.Position(3);
fig.PaperSize = [paperwidth paperheight];
fig.PaperUnits = 'normalized';
fig.PaperPosition = [0 0 1 1];
% Generates the pdf
drawnow;
print(fig, ['foo' num2str(paperwidth) '.pdf'], '-dpdf');
end
0 Comments
Accepted Answer
Raunak Gupta
on 29 Jan 2020
Hi,
I tried with the code provided in the question and I saw that Legend FontSize is properly getting updated. You may see the attached pdfs with 100% size (Not the default fit page version while viewing in a pdf reader). So, the legend’s text is getting updated in terms of pagewidth. Since the colorbar icon near the Legend text is not dependent on the pagewidth and cannot be modified, that might look different when looking the pdf and out of sort. Currently changing the size of colorbar icon manually is not supported but the Legend FontSize is properly getting updated as mentioned here.
Hope this clear the query.
2 Comments
Raunak Gupta
on 30 Jan 2020
Hi,
I have brought this issue to the notice of our developers. They will investigate the matter further. Also I have attached the Use Case that is mentioned in the last comment.
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!