The default font size is MATLAB

I found that I can put set(0, 'DefaultAxesFontSize',14) in the startup.m file, which then changes the default font size of the ticks, axis labels, and the name of my numbers. Is it possible to have a separate default font size for title labels or axes?

+6
source share
1 answer

You cannot have a separate default font size for headings and labels with standard mechanisms. If you want to overload the marking commands, you can get closer. The easiest way is to modify xlabel to allow the default font. You will need to add

 if ~isempty(getappdata(ax, 'DefaultAxesXLabelFontSize')) set(h, 'FontSize', getappdata(ax, 'DefaultAxesXLabelFontSize')); else if ~isempty(getappdata(get(ax, 'parent'), 'DefaultAxesXLabelFontSize')) set(h, 'FontSize', getappdata(get(ax, 'parent'), 'DefaultAxesXLabelFontSize')); elseif ~isempty(getappdata(0, 'DefaultAxesXLabelFontSize')) set(h, 'FontSize', getappdata(0, 'DefaultAxesXLabelFontSize')); end end 

immediately before

 set(h, 'String', string, pvpairs{:}); 

If you do not want to modify the main file, you can reload xlabel

 function varargout = xlabel(varargin) ax = axescheck(varargin{:}); if isempty(ax) ax = gca; end oldPath = pwd; cd([matlabroot, filesep, 'toolbox', filesep, 'matlab', filesep, 'graph2d']); xlabel = str2func('xlabel'); cd(oldPath); oldFontsize = get(ax, 'FontSize'); if ~isempty(getappdata(ax, 'DefaultAxesXLabelFontSize')) set(ax, 'FontSize', getappdata(ax, 'DefaultAxesXLabelFontSize')); else if ~isempty(getappdata(get(ax, 'parent'), 'DefaultAxesXLabelFontSize')) set(ax, 'FontSize', getappdata(get(ax, 'parent'), 'DefaultAxesXLabelFontSize')); elseif ~isempty(getappdata(0, 'DefaultAxesXLabelFontSize')) set(ax, 'FontSize', getappdata(0, 'DefaultAxesXLabelFontSize')); end end varargout{1:nargout} = xlabel(varargin{:}); set(ax, 'FontSize', oldFontsize); if ~nargout varargout = {}; end end 

In any case, you can set the default font size with

 setappdata(0, 'DefaultAxesXLabelFontSize', 36) 

or

 setappdata(gcf, 'DefaultAxesXLabelFontSize', 36) 

or

 setappdata(gca, 'DefaultAxesXLabelFontSize', 36) 

Note that it uses setappdata , not set .

+6
source

Source: https://habr.com/ru/post/913703/


All Articles