Is there a potential bug in the labeling function of the levelplot?
This issue arises because levelplot uses a fixed font size when setting the legend. When different level plots are combined into one figure and the figure is resized, the legend fonts for each subplot don't seem to adjust according to the adaptive size of the MATLAB figure window. The test results are shown in the following figure:
The likelihood of this issue occurring is low, and it can be mitigated by not setting a fixed font size, allowing MATLAB to handle it automatically. The test code is as follows: clc, clear, clf;
% Experimental parameter---------- Exp.mwFreq = 9.8; % 9.8404 Exp.Range = [0 900]; Exp.nPoints = 1e4;
Exp.MolFrame = [0 0 0]*pi./180; Exp.SampleFrame = [0 0 0]; % z
% Exp.CrystalSymmetry = 141; Exp.Harmonic = 1;
Opt.Verbosity = 2;
% ion .............. Sys.S = 1/2; Sys.g = [8 4 2]; Sys.lw = [2 0];
subplot(2,2,1);
[b,spc,trans] = pepper(Sys,Exp,Opt);
spc = normalize(spc,'range',[0 1]);
plot(b,spc,'linewidth',1);
axis tight;
xlabel('Magnetic field (mT)');
ylabel('Intensity (a.u.)');
subplot(2,2,2); Ori = 'x'; Opt.SlopeColor = true; levelsplot(Sys,Ori,Exp.Range,Exp.mwFreq,Opt); xlabel('magnetic field (mT)'); ylabel('energy (GHz)');
subplot(2,2,3); Ori = 'y'; Opt.SlopeColor = true; levelsplot(Sys,Ori,Exp.Range,Exp.mwFreq,Opt); xlabel('magnetic field (mT)'); ylabel('energy (GHz)');
subplot(2,2,4); Ori = 'z'; Opt.SlopeColor = true; levelsplot(Sys,Ori,Exp.Range,Exp.mwFreq,Opt); xlabel('magnetic field (mT)'); ylabel('energy (GHz)');
The legend is displayed using text(...), which uses a default font size that depends on the system and locale. I don't see a simple way to make this font size adaptive.
The fixed FontSize setting has been removed, while keeping FontUnits set to normalized. This allows MATLAB to automatically adjust the font size, ensuring that text scales dynamically with the figure window. ?Wouldn't this modification potentially disrupt other font size settings? Would it be better to avoid setting font sizes altogether in this part?
coldes:
text(xl(1),yl(1),'','Tag','infotext','VerticalAlignment','bottom', 'FontUnits','normalized');
text(hLevelsAxes,xl(1),yl(2),oristr,'VerticalAl','top', 'FontUnits','normalized');
if ~isempty(hText) set(hText,'String',infostr); % Update text position and ensure consistent font settings if ~isempty(infostr) hText.Position(1:2) = [hParent.XLim(1) hParent.YLim(1)]; set(hText,'FontUnits','normalized'); end end
It looks like using normalized for FontUnits leads to text that's way too small when the axes is made smaller. MATLAB apparently has another method of scaling font size that is used for axis labels. Try h = xlabel('somehting') and then look at h.FontSize as you resize the figure window.