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

조회 수: 220 (최근 30일)
David Slater
David Slater 2020년 5월 29일
댓글: Giuseppe Degan Di Dieco 2021년 4월 27일
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?
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 4월 27일
Dear Cris,
your solution worked for me too.
Thanks for your brilliant help.
Best!

댓글을 달려면 로그인하십시오.


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