I can't seem to change figure font name

I run the following simple code and get Helvetica as a font.
fntsz=10;
font='LibreBaskerville-Regular';
axes1=axes('FontName',font,'FontSize',fntsz);
plt1=plot(TDMAINVTAO{1}.sd(:,1),TDMAINVTAO{1}.sd(:,2),'b');
set(plt1,'parent',axes1)
xlabel('Diameter (nm)')
ylabel('dN/dD{p} (#/cc/nm)')
I have tried the following as well...
set(findall(fig1,'-property','FontName'),'FontName',font)
When I try to change the axes font using the axes property editor, LibreBaskerville-Regular is not available.
However, when I run listfonts, LibreBaskerville-Regular is in the list.
I am currently running R2012a.
Chris

 Accepted Answer

Set the default values for the fonts, when you create the figure:
font = 'LibreBaskerville-Regular';
figure('DefaultTextFontName', font, 'DefaultAxesFontName', font);
axes;
text(0.5, 0.5, 'Hello!');
Now the text and the tick labels use the wanted font.

5 Comments

I am accepting this answer because I learned to change the default values for the figure. Saves many steps. Thanks. As for the solution to the problem, I think the problem was more my inability to tell the font from others (namely Helvetica). Is there anyway to make the font show up in the figure editor too?
The actual problem is:
using the axes property editor, LibreBaskerville-Regular is not available
This means that listfonts shows fonts, which are not available in the property editor. Then my guess is, that the font type is not applicable in Matlab. Perhaps a TrueType or PostScript problem. I had some TrueType fonts, which worked on a PC, but MacOS rejected to install them, because they are "damaged".
So does the posted code let the wanted font appear in the figure? If this works, the next step would to examine, why the property editor does not offer this font.
Everything appears to be fine in the figure (I am not a font specialist either). I can query the property using "get", and the correct font (LibreBaskerville-Regular) is returned. I then try to view the property through the editor. The editor shows the property to be Helvetica, and LibreBaskerville-Regular is not even an option.
Which "editor" do you mean?
If I have the figure open, I click edit in the menu bar, and select axis properties. Then select the font tab. The font name will be listed as Helvetica. If I query through get(), it will return LibreBaskerville-Regular.

Sign in to comment.

More Answers (1)

It looks like the 'NextPlot' (normally manipulated with hold on and hold off) behavior includes things like FontName for the axes. Try:
font='LibreBaskerville-Regular';
axes1=axes();
plt1=plot(axes1,TDMAINVTAO{1}.sd(:,1),TDMAINVTAO{1}.sd(:,2),'b');
set(axes1,'FontName',font,'FontSize',fntsz);

2 Comments

Yeah, this is it
You can change your accepted answer if this one is more accurate or complete.

Sign in to comment.

Categories

Products

Asked:

on 1 Dec 2017

Commented:

on 18 Jul 2018

Community Treasure Hunt

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

Start Hunting!