0
votes

I have prepared a plot in Matlab using legends to identify the various traces. I have adjusted the font size in the legends and the axis labels appropriately to produce decent looking plots. The plots look fine on-screen, but when I save-as to any reasonable format (PDF, PNG, BMP, etc) the font size information in the legends is willfully disregarded.

This results in legends on plots and subplots that look horrendous, as the fonts expand back to their default size, run off the sub-plots, overlap, etc.

I can actually see the fonts revert back to default, briefly, during the save-as operation, and then change back to their correct sizes. How can I avoid this problem and force Matlab to do the obviously correct and intended thing?

Example code to set the fonts:

set(gca,'xticklabel',{'1','2', '4', '8', '16', '32', '64', '128', '256'}, 'fontsize', 4)
leg = legend('One Text, Two Text','Red Text, Blu Text','Location','southwest')
set(leg, 'fontsize', 2);

This is Matlab 2016a under Windows 10.

2
I would recommend using export_figSuever

2 Answers

0
votes

You could add 'FontUnits','points' to the set function. And depending on how you save the plot, you might use print instead of the save as function of MATLAB.

Below is the script I use for printing my figures. It's based on this:

filename = 'myfile';       % figure to be printed
uiopen(myfile,1)
axis([0 200 -0.1 0.15])    % scale the axis
set(gca,...
    'Units','normalized',...
    'YTick',-0.1:0.05:0.15,...
    'XTick',0:50:200,...
    'Position',[.15 .2 .75 .7],...
    'FontUnits','points',...
    'FontWeight','normal',...
    'FontSize',9,...
    'FontName','Times')
ylabel({'f(x)'},...           % {} allows to add Latex code in the label
    'FontUnits','points',...
    'interpreter','latex',...
    'FontSize',14,...
    'FontName','Times')
xlabel({'$x$'},...
    'FontUnits','points',...
    'interpreter','latex',...
    'FontWeight','normal',...
    'FontSize',14,...
    'FontName','Times')
legend({'$f(x) = x$'},...
    'FontUnits','points',...
    'interpreter','latex',...
    'FontSize',14,...
    'FontName','Times',...
    'Location','NorthEast')
title({'This is: $f(x) = x$'},...
    'FontUnits','points',...
    'interpreter','latex',...
    'FontWeight','normal',...
    'FontSize',14,...
    'FontName','Times')
title('This is: $f(x) = x$')
legend('$f(x) = x$')

print(filename,'-depsc2');        % print to filename.eps
0
votes

Have you ever tried to check the option in the following:

Preference -> MATLAB -> Figure Copy Template -> Copy Options -> Size -> Match figure screen size?