Is there a way to define a default axis position, similar to defaultFigurePosition?

16 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2021-2-12
编辑:Jan 2021-2-12
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 个评论
Jan
Jan 2021-2-12
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
Martin 2024-3-27
Hello @Jan,
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by