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

41 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Jan
Jan el 12 de Feb. de 2021
Editada: Jan el 12 de Feb. de 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 comentarios
Jan
Jan el 12 de Feb. de 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 el 27 de Mzo. de 2024 a las 16:02
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by