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

16 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Jan
Jan am 12 Feb. 2021
Bearbeitet: Jan am 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 Kommentare
Jan
Jan am 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
Martin am 27 Mär. 2024
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by