Clear Filters
Clear Filters

How can I change the font size of tick labels on the axes of a graph?

395 views (last 30 days)
I have tried all of the suggestions in fx, Help and answers to other people's questions, but I cannot make any of them work in Matlab 2020a.

Answers (2)

Cris LaPierre
Cris LaPierre on 29 May 2020
Edited: Cris LaPierre on 29 May 2020
It's in the documentation under axes properties:
ax.FontSize = 20
You can also change a single axis by specifying that axis:
ax.XAxis.FontSize = 20
Cris LaPierre
Cris LaPierre on 2 Jun 2020
You likely replied to an email notification from MATLAB Central. Replies are not actually directed to anyone.
I've poked around in your code. I didn't attempt to explore every plot, but if I were you, I would probably set the properties this way.
title(strcat('Basilar Membrane Velocity Transfer Function, Excitation @',Stringt,sprintf('\n Frequency = %0.0f Hz,',f(fn)),Comp))
ylabel(strcat('Basilar Membrane velocity amplitude (dB)',Stringy))
xlabel('Distance from Stapes (mm)')%lgd.Title.String = 'Frequency (kHz)';
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
ax.XLabel.FontSize = 24;
ax.YLabel.FontSize = 14;
ax.Title.FontSize = 18;
Was there a particular plot that was not working?
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco on 27 Apr 2021
Dear Cris,
your solution worked for me too.
Thanks for your brilliant help.

Sign in to comment.

David Slater
David Slater on 3 Jun 2020
Thanks for your response. Your suggested way of specifying font sizes is much more rational than mine, and so I have tried it both for one plot in my full script and for the simplified script below. Running the script after executing a clear command results in your graph with 20pt tick labels, followed by my graph still with 12pt tick labels and no title or axis titles. Any thoughts?
plot(1:5 )
ax=gca ;
ax.FontSize = 20
title('Measured and Predicted Hearing Loss (Reduction in BM Velocity) with no Bubble')
ylabel('Post Implant Hearing Loss (dB)')
xlabel('Frequency (Hz)')
ax.XAxis.FontSize = 20;
ax.YAxis.FontSize = 20;
ax.XLabel.FontSize = 20;
ax.YLabel.FontSize = 20;
ax.Title.FontSize = 36;
semilogx(f,20*log10(HL0),'LineWidth', 3,'color','r')
grid on
There are two graphs that particularly need a larger font for the tick labels: figures 6 and 7 in my full script. I have deleted the many sections that create the other graphs, and I have attached the result. (To reduce the run time, I have also reduced the number of iterations necessary in the sections that do the calculations; this makes the graphs a bit more notchy, but it makes no difference to font sizes.)
David Slater
David Slater on 10 Jun 2020
I haven't heard from you in a while; do I need to open a new question, or do you still have this in hand?
David Slater
David Slater on 1 Jul 2020
Because I have heard nothing further from you or anyone at Mathsoft in weeks, I had to try to find the problem myself by trial and error. Mathsoft and/or its customers may be interested in what I have found. The problem appears to be with the "load" function. If I load the workspace with a .mat file, this prevents the script from changing the font sizes. If I delete the "load" command from the script, then the code that you suggested and the code that I was using previously both work. I can manage without using the "load" function, but doing so is inconvenient, and it will become more so as my project develops. Am I doing something wrong, or is this a bug?
Please respond to this, even if only to ask me to open a new question.

Sign in to comment.


Find more on Graphics Object Identification in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!