필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Paul
Paul 2020년 9월 7일
댓글: Paul 2020년 9월 21일
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.

답변 (1개)

Sourabh Kondapaka
Sourabh Kondapaka 2020년 9월 17일
Hi,
I have brought this issue to the notice of our developers. They will investigate the matter further.
  댓글 수: 4
Sourabh Kondapaka
Sourabh Kondapaka 2020년 9월 21일
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 2020년 9월 21일
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

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by