I can't get the correct figure font name

I would like to use 'NewCenturySchoolBook' or 'Palatino' but the font does not change. Note that it does change for 'Times' or 'Palatino Linotype'. Am I missing something?
font = 'NewCenturySchoolBook';
figure('DefaultTextFontName',font,'DefaultAxesFontName',font);
plot(1:5,8:12)
legend('random stuff')
xlabel('also random')
ylabel('what is going on here')

6 Commenti

It does change for me.Increase the font size and see the difference because it's too small.
I can increase the size as much as I want, it will change, say, for 'times' but not for 'Palatino'. I don't get what is wrong.
Can you upload the picture for working and not working fonts?
If not only way is to report a bug to Mathworks support team.
Left is with 'times' (working), right is 'newcenturyschoolbook' (not working)
Just contact Mathworks team if you are not satisfied with the font.

Accedi per commentare.

 Risposta accettata

Star Strider
Star Strider il 28 Ago 2018
Use the listfonts (link) function to find the fonts available on your system.
The documentation does not mention in what MATLAB release the function was introduced.

5 Commenti

I did that and I can confirm both 'NewCenturySchoolBook' and 'Palatino' are available on my machine. But they won't display.
Definitely strange. When I executed this:
fnts = listfonts;
findfont = strfind(fnts, 'New');
idx = find(cellfun(@(x)~isempty(x),findfont));
fnts_New = fnts(idx)
the 'NewCenturySchoolbook' was listed. However, when I checked the fonts installed on Win10 on this machine, it wasn’t listed, even after doing a File Explorer search for it.
The closest I can get to 'Palatino' when I searched is 'Palatino Linotype'. Try that.
You might want to bring to the attention of MathWorks that the font names recovered by listfonts do not necessarily correspond to the fonts installed on Windows. (If you are using another OS, those may differ.)
My only other suggestion is to find a source of fonts on the Interweb (when I last checked a few years ago, there were several and most were free), and download and install the ones you want. This is essentially trivial to do.
When he said they "don't display," I think he means on the graph, not as displayed by listfonts().
Thanks @Star Strider I think you nailed it. Matlab listfonts indicates I can use the newcent font, but it's not installed on my Windows 10 machine, and therefore I can't. Indeed Mathworks should correct for this.
My pleasure.
I agree. If a font isn’t installed, it’s not available.
If my Answer helped you solve your problem, please Accept it!

Accedi per commentare.

Più risposte (1)

Since I didn't see 'DefaultTextFontName' or 'DefaultAxesFontName' as options listed in the help for the figure function, and not even when I did
properties(gcf);
I did this, which works:
listfonts
font = 'NewCenturySchoolBook';
hFig = figure('DefaultTextFontName',font, 'DefaultAxesFontName',font);
properties(hFig)
plot(1:5,8:12)
ax = gca
legend('random stuff')
fontSize = ax.FontSize;
caption = sprintf('The font is %s with size %f', ax.FontName, fontSize);
title(caption, 'FontSize', fontSize);
xlabel('X Axis', 'FontSize', fontSize)
ylabel('Y Axis', 'FontSize', fontSize)
uiwait(msgbox('Click OK to see the fonts Change', 'modal'));
ax.FontName = 'NewCenturySchoolBook'
ax.FontSize = 18; % Change font size to 18
fontSize = ax.FontSize;
caption = sprintf('The font is %s with size %f', ax.FontName, fontSize);
title(caption, 'FontSize', fontSize);
Basically I set the fonts for the axes, not the figure.

Categorie

Prodotti

Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by