How can I change the font size of the current axis?

2.102 visualizaciones (últimos 30 días)
Hassan el 15 de Jun. de 2011
Respondida: Sulaymon Eshkabilov el 20 de En. de 2023
How can I change the font size of the axes of the current graph without creating new axes? For example, if we have this plot already, how can I change the font size?
x = rand(10,10);
y = rand(10,10);

Respuesta aceptada

Matt Fig
Matt Fig el 28 de Abr. de 2022
Editada: MathWorks Support Team el 28 de Abr. de 2022
To change the font size, set the FontSize property on the axes object after plotting. For example:
x = rand(10,10);
y = rand(10,10);
Starting in R2022a, you can use the “fontsize” function to change the font size for any graphics object that has text associated with it. In this case, pass the axes object to the “fontsize” function followed by the desired font size in points. For example:
You can also change the font name using the “fontname” function. The font you specify must be installed on your system. For example, change the font of the current axes to Courier:
  3 comentarios
Viktor Erdelyi
Viktor Erdelyi el 16 de Mayo de 2022
On my end, I had to specify the fontsize unit as shown here.

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 16 de Mayo de 2022
See attached demo to see how you can independently change a wide variety of things in your axes.
  3 comentarios
Rhythm Analyst
Rhythm Analyst el 26 de Oct. de 2022
Solved the issue; I was using ax=gca; for both 'yyaxis left' and 'yyaxis right'. Fix was to have ax1 for left yaxis and ax2 for right yaxis; as far as I can tell thats what fixed it anyway...
Thanks for the response.

Iniciar sesión para comentar.

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 20 de En. de 2023
There is one minor correction with one of the otptions proposed by @Mat Fig using fontsize() the unit has to be specified:
x = 1:5;
y = randi(5,1,5);
fontsize(gca, 15,'points') % 'pixels', 'centimeters', 'inches'


Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by