How to Change the Font Size on MATLAB Plots

This post is intended for people having trouble getting their font sizes to change when making plots in MATLAB.  I spent about 3 hours trying to figure this out, and just did courtesy of these people:

http://www.mathworks.com/matlabcentral/answers/1238-font-size-changes-in-figures

View their solution, or see the steps below.  The solution will fix the following problem:

Suppose you are trying to set the font size of the axes on your graph.  You type:

set(gca, ‘FontSize’, 20)

But for some reason the font stays stubbornly at 10, or 12, or whatever.  You then edit your startup.m file to set the default size when Matlab starts up.  You type the following line:

set(0,’DefaultAxesFontSize’,20)

You restart Matlab, and the axes are still not showing up with 20 point font.

Here’s the steps to fix this problem:

1.  Open MATLAB and type “userpath”.

2.  In the first directory shown, create a text file called “startup.m”, or, if it is already there, open it for editing.  More detailed instructions and explanations of startup.m and userpath are here:

http://www.mathworks.com/help/techdoc/matlab_env/bs6j57e-1.html#bs6j57e-3

http://www.mathworks.com/help/techdoc/matlab_env/f8-4994.html#brlkmbe-1

3.  Write the following lines in startup.m:

set(0,’defaultAxesFontName’, ‘Arial’)

set(0,’defaultTextFontName’, ‘Arial’)

set(0,’defaultUIControlFontName’, ‘Arial’)

Keep in mind you can change “Arial” to any font name that exists in Matlab.  The point is to change the default font that Matlab uses.  Apparently there is a bug in Matlab where the default font makes it impossible to change the font properties.  I am not sure why this is the case but it certainly wasted a bunch of my time in trying to get around it.

Advertisements

About glossarch

The word "glossarch" doesn't exist. At least, not yet. But let's pretend it does for a second. The first part is "gloss," a word that comes to us from Ancient Greek via Latin and English. It means "language." The second part also comes from Ancient Greek and can mean "having power over." So "glossarch" means simply "language controller." So what am I doing making up words? Well, I made up an entire language once. It's called Angosey. So I'm the Glossarch of Angosey. I'm currently a doctorate student in volcano seismology (a branch of geophysics). I enjoy writing fiction and poetry, launching balloons, programming, and hanging out with my lovely wife! Follow me on Twitter! Writing and language creation: @glossarch Balloons and science: @bovineaerospace
This entry was posted in SyntaxError (Programming) and tagged , . Bookmark the permalink.

One Response to How to Change the Font Size on MATLAB Plots

  1. Very interesting, though, to be honest, I have NO IDEA what you’re talking about. 🙂 But thank you for the information, should I ever go back and finish that math degree 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s