Changing Fonts Size in Matlab Plots
Asked Answered
N

7

77

I want to change Font Size for xlabel, ylabel, axis size, legend font size a.k.a everything at once, is this possible? By default, font is Helvetica 10.

Is there way to change this?

I want to use 'FontSize',14, for x or y labels.

Nonintervention answered 19/1, 2012 at 22:43 Comment(0)
C
60

Jonas's answer is good, but I had to modify it slightly to get every piece of text on the screen to change:

set(gca,'FontSize',30,'fontWeight','bold')

set(findall(gcf,'type','text'),'FontSize',30,'fontWeight','bold')
Costotomy answered 11/7, 2012 at 18:55 Comment(1)
How would one modify this to include the font type for the numbers on the axes?Higgledypiggledy
F
51

If you want to change font size for all the text in a figure, you can use findall to find all text handles, after which it's easy:

figureHandle = gcf;
%# make all text in the figure to size 14 and bold
set(findall(figureHandle,'type','text'),'fontSize',14,'fontWeight','bold')
Fogarty answered 19/1, 2012 at 22:58 Comment(1)
See answer by @sergeyf below for changing the axis label font as well.Jacki
C
45

It's possible to change default fonts, both for the axes and for other text, by adding the following lines to the startup.m file.

% Change default axes fonts.
set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize', 14)

% Change default text fonts.
set(0,'DefaultTextFontname', 'Times New Roman')
set(0,'DefaultTextFontSize', 14)

If you don't know if you have a startup.m file, run

which startup

to find its location. If Matlab says there isn't one, run

userpath

to know where it should be placed.

Calorie answered 21/1, 2012 at 23:18 Comment(0)
F
9

If anyone was wondering how to change the font sizes without messing around with the Matlab default fonts, and change every font in a figure, I found this thread where suggests this:

set(findall(fig, '-property', 'FontSize'), 'FontSize', 10, 'fontWeight', 'bold')

findall is a pretty handy command and in the case above it really finds all the children who have a 'FontSize' property: axes lables, axes titles, pushbuttons, etc.

Hope it helps.

Foraminifer answered 12/11, 2013 at 0:4 Comment(0)
L
5

To change the title font size, use the following example

title('mytitle','FontSize',12);

to the change the graph axes label font size, do the following

axes('FontSize',24);
Lathi answered 19/1, 2012 at 22:53 Comment(0)
A
5

Jonas's answer does not change the font size of the axes. Sergeyf's answer does not work when there are multiple subplots.

Here is a modification of their answers that works for me when I have multiple subplots:

set(findall(gcf,'type','axes'),'fontsize',30)
set(findall(gcf,'type','text'),'fontSize',30) 
Aldridge answered 4/9, 2013 at 11:43 Comment(0)
B
4

To change the default property for your entire MATLAB session, see the documentation on how default properties are handled.

As an example:

set(0,'DefaultAxesFontSize',22)
x=1:200; y=sin(x);
plot(x,y)
title('hello'); xlabel('x'); ylabel('sin(x)')
Brookweed answered 19/1, 2012 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.