Why does the font size in my Axes change spontaneously?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Bora Eryilmaz
2022-12-20
编辑:Bora Eryilmaz
2022-12-20
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
ax.XAxis.Label.FontSize % 8 as expected
ax.XAxis.Label.FontSize = 8;
ax.XAxis.FontSize = 10;
ax.XAxis.Label.FontSize % NOT 8 as expected
ax.XAxis.FontSize % 10 as expected
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!