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

219 次查看(过去 30 天)
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.

回答(2 个)

Cris LaPierre
Cris LaPierre 2020-5-29
编辑:Cris LaPierre 2020-5-29
It's in the documentation under axes properties:
plot(1:5)
ax=gca;
ax.FontSize = 20
You can also change a single axis by specifying that axis:
ax.XAxis.FontSize = 20
  5 个评论
Cris LaPierre
Cris LaPierre 2020-6-2
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=gca;
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?

请先登录,再进行评论。


David Slater
David Slater 2020-6-3
Cris,
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?
figure(1)
plot(1:5 )
ax=gca ;
ax.FontSize = 20
f=logspace(log10(20),log10(20000),100);
HL0=linspace(0,50);
figure(6)
title('Measured and Predicted Hearing Loss (Reduction in BM Velocity) with no Bubble')
ylabel('Post Implant Hearing Loss (dB)')
xlabel('Frequency (Hz)')
ax=gca;
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.
  5 个评论
David Slater
David Slater 2020-6-10
Cris,
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.
David Slater
David Slater 2020-7-1
Cris,
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.
David.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by