Why does the font size in my Axes change spontaneously?

1 view (last 30 days)
I have an application that has 3 axes inside of it - named 'Top', 'Middle', and 'Bottom'. They are used to compare similar sets of data.
My application uses the standard startup callback startupFcn
I have a loop in startupFcn that goes through the 3 axes and attempts to set them all to standard font sizes and colors I define. I also embed handles to the axes in the App variables for shorter paths to properties I use commonly. Here is the code excerpt from startupFcn :
numLocations = numel( app.locations );
for loc = 1:numLocations
thisLocation = app.locations{loc};
thisAxes = getDMPart(app, 'axes', thisLocation);
%Create shortcut handles to common axes objects, and change to
%defaults
shortAxes = struct();
shortAxes.handle = thisAxes;
shortAxes.title = title(thisAxes, [thisLocation, ' Chart']);
shortAxes.title.Color = app.axesTitleColor;
shortAxes.title.FontSize = app.axesTitleSize;
shortAxes.X = thisAxes.XAxis;
shortAxes.Y = thisAxes.YAxis;
%Axes Properties Set
shortAxes.X.FontSize = app.axesDataSize;
shortAxes.Y.FontSize = app.axesDataSize;
shortAxes.X.Label.String = 'Time';
shortAxes.X.Label.FontSize = app.axesLabelSize;
shortAxes.X.Label.FontWeight = 'bold';
shortAxes.Y.Label.String = 'Variables';
shortAxes.Y.Label.FontSize = app.axesLabelSize;
shortAxes.Y.Label.FontWeight = 'bold';
%Store in App
app.axesApp.(thisLocation) = shortAxes;
end
FYI, app.locations axesDataSize, and axesLabelSize are all constant properties in my app:
locations = { 'Top', 'Middle', 'Bottom' };
%Axes Properties
axesDataSize = 8;
axesLabelSize = 10;
axesTitleColor = [1 1 1];
axesTitleSize = 14;
And axesApp is a public property of my app, set to a struct as follows:
axesApp = struct( ...
'Top', '', ...
'Middle', '', ...
'Bottom', '' ...
); %Set of pointers to axes and specific axes properties
However, after I run my App, the X and Y label sizes are 7.5!
The really bizarre thing, is when I try to troubleshoot and put a breakpoint at each assignment line in startupFcn - it works perfectly. The app pops up with the label at size 10 and the axes marks at size 8, as expected. The labels only shrink to 7.5 if I run normally, without breakpoints. I don't have anything else running in parallel while staruptFcn is running. Why would this happen?

Answers (1)

Bora Eryilmaz
Bora Eryilmaz on 20 Dec 2022
Edited: Bora Eryilmaz on 20 Dec 2022
axis.FontSize and axis.Label.FontSize are not independent properties. Setting axis.FontSize will not affect axis.Label.FontSize, but setting axis.Label.FontSize will affect axis.FontSize. Or, it could be the other way around. :)
clc
cla
ax = gca;
ax.XAxis.FontSize = 10;
ax.XAxis.Label.FontSize = 8;
ax.XAxis.FontSize % 10 as expected
ans = 10
ax.XAxis.Label.FontSize % 8 as expected
ans = 8
ax.XAxis.Label.FontSize = 8;
ax.XAxis.FontSize = 10;
ax.XAxis.Label.FontSize % NOT 8 as expected
ans = 11
ax.XAxis.FontSize % 10 as expected
ans = 10

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!