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!