fontname

Sets the font name of the text in a figure or graphics object.

Category: Graphics > Formatting and Annotation

Syntax

fontname(name)

Sets the font of the text in the current figure to name.

fontname(obj, name)

Sets the font for the figure, axes or other container obj and the text inside it.

Description

fontname is a shortcut for setting the FontName property on every object under obj that has one, so a single call restyles titles, labels and tick labels together.

The function does not draw anything by itself. It affects the text that already exists when it is called.

Input arguments

name
Font name as text, such as 'Arial'. The value 'default' restores the default font.
obj
Handle to a figure, axes or other graphics object.

Example

Change the font of a plot

plot(1:4)
title('Trend')
fontname('Arial')
ax = gca;
ax.Title.String
Output
ans = 'Trend'

The figure is drawn below the code.

Notes

In MatLivre, fontname with no arguments is an error and the function returns no value; the MATLAB form that returns the current font name is not available. Use the FontName property of an object to read it.

See also

fontsize title xlabel text gca