MATLAB Answers

Can the Font Size of an Axis Label be Reliably Determined Programatically

1 view (last 30 days)
Paul
Paul on 7 Sep 2020
Commented: Paul on 21 Sep 2020
AFAICT, there are three ways to set the font size of an axis label and there are three ways to get the font size of an axis lable. However, the three ways to get the font size of the axis label can return different answers and seem to depend on how the font size of the axis label was set in the first place. As will be shown, they are even inconsistent if the user takes no action to change the font size of the axis lablel from the default. Here is the code that demonstrates:
figure(10)
plot(rand(6))
xlabel('XLABEL')
[get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(1)
plot(rand(6))
xlabel('XLABEL')
set(gca,'LabelFontSizeMultiplier',1.5)
[get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(2)
plot(rand(6))
xlabel('XLABEL')
set(get(gca,'XAxis'),'FontSize',15)
[get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(3)
plot(rand(6))
xlabel('XLABEL')
set(get(get(gca,'XAxis'),'Label'),'FontSize',15)
[get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
ans =
11 10 11
ans =
15 10 11
ans =
11 15 11
ans =
11 10 15
Interestingly enough, the middle result in the first answer is incorrect (I think?), even before actively changing the label fontsize.
It certainly looks like that there is NO WAY to reliably, programmatically determine the font size of the label w/o knowing how it was set in the first place. Depending on how the label font size was set, and depending on which one of the three interrogation methods are used, one might or might not get the correct answer. This is very troubling, is it not? Especially for those who have to work with figures for which the code that generated the figure is not available.
I actually ran into this issue some time ago and don't recall all of the details of what I saw in the doc. However, I do recall that each individual methods for setting and getting the fontsize could be found, but there was no discussion of how they influence each other, at least not that I could find.

  0 Comments

Sign in to comment.

Answers (1)

Sourabh Kondapaka
Sourabh Kondapaka on 17 Sep 2020
Hi,
I have brought this issue to the notice of our developers. They will investigate the matter further.

  4 Comments

Show 1 older comment
Sourabh Kondapaka
Sourabh Kondapaka on 18 Sep 2020
Hi Paul,
I had already raised an escalation and had brought up this issue to the concerned developers. You need not submit a bug report.
Thanks,
Sourabh
Sourabh Kondapaka
Sourabh Kondapaka on 21 Sep 2020
Hi Paul,
The inconsistency in values is because they are updated at the end of the script. If you would like to update it immediately and see the correct values use the "draw now" command.
Please find an example below:
figure(10);
plot(rand(6))
xlabel('XLABEL');
k = gca;
k.FontSize = 19;
drawnow
disp(get(get(gca,'XAxis'),'FontSize'));
get(get(get(gca,'XAxis'),'Label'),'FontSize')
Paul
Paul on 21 Sep 2020
Maybe I'm using it incorrectly, but I don't see that drawnow helps. However, it actually changes one of the results for figure 2, though not necessarily in a good or correct way. Here is the updated script and the results:
close all
figure(10)
plot(rand(6))
xlabel('XLABEL')
figure10 = [get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(1)
plot(rand(6))
xlabel('XLABEL')
set(gca,'LabelFontSizeMultiplier',1.5)
drawnow
figure1 = [get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(2)
plot(rand(6))
xlabel('XLABEL')
set(get(gca,'XAxis'),'FontSize',15)
drawnow
figure2 = [get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure(3)
plot(rand(6))
xlabel('XLABEL')
set(get(get(gca,'XAxis'),'Label'),'FontSize',15)
drawnow
figure3 = [get(gca,'FontSize')*get(gca,'LabelFontSizeMultiplier') get(get(gca,'XAxis'),'FontSize') get(get(get(gca,'XAxis'),'Label'),'FontSize')]
figure10 =
11 10 11
figure1 =
15 10 15
figure2 =
1.1000e+01 1.5000e+01 1.6500e+01
figure3 =
11 10 15

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!