Is there a way to define a default axis position, similar to defaultFigurePosition?
16 views (last 30 days)
Show older comments
When plotting with the plot command, you can change the position of the axes using e.g.:
set(gca,'Units', 'normalized','Position',[0.1 0.1 0.9 0.9])
which is similar to how a figures position can be changed.
Is there a setting for the default axis positions, analog to setting a default position for figures:
set(0, 'defaultFigurePosition', [0.25 0.25 0.7 0.7])
Or is there any other to set the plot axes in a particular way by default?
0 Comments
Accepted Answer
Jan
on 12 Feb 2021
Edited: Jan
on 12 Feb 2021
Yes.
% A strange small size to be sure, that it works:
set(groot, 'defaultAxesPosition', [0.25, 0.25, 0.2, 0.2])
figure;
plot(1:10)
This is a bad idea, because it modifies all folling axes objects. It is smarter to do this for your own figures only:
% Reset the stuff from above:
set(groot, 'defaultAxesPosition', get(groot, 'factoryAxesPosition'))
figure('defaltAxesPosition', [0.55, 0.55, 0.2, 0.2])
plot(1:10)
Using 0 as root object is outdated since 2014. Prefer groot.
4 Comments
Jan
on 12 Feb 2021
You find some documentation by:
docsearch factory
For all possible parameters see:
a = get(groot, 'Factory');
a = get(groot, 'Default');
Limiting the effect for axes created implicitly by plot is not possible.
Martin
on 27 Mar 2024
Is your solution still working for uifigure/uiaxes in Matlab 2023b? I am using the Default* properties for years, but now I am moving to uifigures and getting problems.
In the examples below the uiaxes does not work....
Working:
%% working figure/axes
hFig = figure();
set(hFig, 'DefaultAxesUnits', 'normalized')
set(hFig, 'DefaultAxesPosition', [0 0 1 1]);
set(hFig, 'DefaultAxesCreateFcn', @(~,~)disp('created'))
hAx = axes(hFig);
disp(get(hAx, 'Units'))
disp(get(hAx, 'Position'))
disp(get(hAx, 'CreateFcn'))
Not working:
%% not working uifigure/uiaxes
hFig = uifigure();
set(hFig, 'DefaultAxesUnits', 'normalized')
set(hFig, 'DefaultAxesPosition', [0 0 1 1]);
set(hFig, 'DefaultAxesCreateFcn', @(~,~)disp('created'))
hAx = uiaxes(hFig);
disp(get(hAx, 'Units'))
disp(get(hAx, 'Position'))
disp(get(hAx, 'CreateFcn'))
The units are still 'pixels', the location is [10 10 400 300] and no 'created' is displayed. BUT disp(get(hAx, 'CreateFcn')) displays correct!
What is going wrong?
Note the property 'DefaultAxesButtonDownFcn' is working for both.
Thanks in advance,
Martin
More Answers (0)
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!