Auto resize of manually added axes

조회 수: 18 (최근 30일)
Michael
Michael 2021년 6월 22일
답변: Prahlad Gowtham Katte 2022년 2월 16일
I need to manually add axes to a figure, but I want the axes I add to automatically resize when I maximize/scale the figure window. When I create the axes using 'subplot.m,' the axes scale when I maximize the window, which is what I want. When mannually adding axes (see code below) the resulting axes don't grow with the window size. How might I do this?
fig_h = figure;
ax_h = uiaxes(fig_h);
I've looked through both the axes and figure object properties for a something related to auto resizing, but haven't found anything. Any bright ideas would be appreciated.
Thanks.
  댓글 수: 2
dpb
dpb 2021년 6월 22일
I'm guessing subplot adds a callback function to the figure that handles it -- probably deep in the bowels of handle graphics internals that isn't visible/exposed to the user.
DGM
DGM 2021년 6월 22일
Two things:
1: What is the 'units' property of the axes object set to? If it's not set to 'normalized', it won't resize with the figure.
2: Like dpb mentioned, more complicated layout management can be accomplished with a callback function that executes when the figure is resized. A figure object can be assigned function handle for the 'ResizeFcn' property. You can create a user-defined function which looks at figure and object geometries and manages them accordingly. Then just set it like so:
set(fig_handle,'resizefcn',@myresizefunction);
or if you want to pass extra parameters to the function (e.g. the current figure handle)
set(fig_handle,'resizefcn',{@myresizefunction,param1,param2});

댓글을 달려면 로그인하십시오.

답변 (1개)

Prahlad Gowtham Katte
Prahlad Gowtham Katte 2022년 2월 16일
Hello,
As per my understanding of the query, you are trying to find out why the axes you added manually is not resizing when figure is resized. The answer as mentioned in the comments Is that your axes’ units should be set to “normalized” but since you have created an axes using “uiaxes()” function the default Units property would be set to “Pixels”.
To change it to normalized the following line would help
ax_h.Units="normalized";
But if you create an axes using axes function, the default Units property is set to be normalized and it resizes without any additional code.
The following links would be helpful to learn more about properties of uiaxes and axes
Hope it resolves the query.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by