How to position a geoaxes figure within a uifigure

20 次查看(过去 30 天)
Hi again everyone,
My learning curve has been steep and im getting frustrated. Maybe its time for a break but before that I want to ask another question.
Im trying to progammatically create a GUI for a processing program im building, I have a script that does everything I want and looks ok but a GUI would be way more helpful, also I dont really want to use the app builder. I think doing it the hard way will help me learn more. Just to start ive read through the documentation extensivly and tried many different options with no luck. I created a function with a few nested functions, when I set up my options and click 'run' I want a world map to show up with all my data plotted on it. Right now I can generate this map with no problem, however it fills the entire GUI, I want to position this figure so it shows up in the bottom left corner of the uifigure. I have other plots that are created that I want to include in the uifigure as well. Right now when I set my options and click run everything pops up as its own figure.
My code below is for the world map, first it concatenates all the lat and long data from each file and plots them so you can see each survey your processing, afterward it plots a surface map for each with depth included. The block of code I have posted here is just to plot the figure, it plots fine like I mentioned but fills the entire uifigure, how do I resize and position this where I want? I have tried a lot of different combinations, when I include gx.Position the map doesnt show up at all. Any help and advise is appreciated. Thank you.
gx = geoaxes;
gx.Parent = (fig);
gx.Position = [100 100 500 500];
geoplot(gx,FinalLat, FinalLong, 'r-*')
geobasemap(gx,'grayterrain')
  1 个评论
Anton Kogios
Anton Kogios 2024-3-22
Hi Bradley, I'd love to help out - could you send your whole code so I can recreate your problem please?
Something you can try is
gx = geoaxes(fig);
This removes the need for your 'gx.Parent = (fig)' line.
Also, MATLAB App Designer is surprisingly really easy to learn and start using. Would recommend.

请先登录,再进行评论。

回答(2 个)

Avni Agrawal
Avni Agrawal 2024-4-3,5:08
Hi @Bradley, I understand that you are trying to position a 'geoaxes' object within a specific area of a 'uifigure'. The key here is to ensure that the 'geoaxes' is a child of the 'uifigure' (or a container within the uifigure), and then to correctly set the 'Position' property.
However, there's a mistake in how you're setting the 'Position' property. The 'Position' property expects values in the format [x y width height], where x and y specify the distance from the left and bottom edges of the parent container, respectively, and 'width' and 'height' specify the size of the component. All values are in pixels.
Given that, your code should look something like this:
% Assuming 'fig' is your uifigure
fig = uifigure('Name', 'My GUI', 'Position', [100, 100, 800, 600]);
% Create geoaxes as a child of the uifigure
gx = geoaxes('Parent', fig);
% Set the position of the geoaxes within the uifigure
% Here, [x y width height] sets the geoaxes to be at the bottom left
% with a width of 500 pixels and a height of 500 pixels.
gx.Position = [10 10 500 500]; % Adjust [x y width height] as needed
% Now plot on the geoaxes
geoplot(gx, FinalLat, FinalLong, 'r-*');
geobasemap(gx, 'grayterrain');
A few key points to remember:
  • Ensure fig is your uifigure object.
  • When setting gx.Parent = fig, you're specifying that the geoaxes is a child of the uifigure, which is correct.
  • Adjust the gx.Position values to position the map exactly where you want it within the uifigure. The first two numbers [10 10] are the bottom-left corner relative to the uifigure, and the last two numbers [500 500] are the size of the geoaxes.
  • If you're placing multiple components within the uifigure, consider using uigridlayout or uiflowcontainer for more flexible and automatic layout management
  • Remember to adjust the Position values to fit the layout you're aiming for.
Please refer to below mentioned documentations link for better understanding:
  1. uifigure Documentation: https://www.mathworks.com/help/matlab/ref/uifigure.html
  2. geoaxes Documentation: https://www.mathworks.com/help/matlab/ref/geoaxes.html
  3. Position Property for UI Components: Here's an example within the uicontrol documentation that explains the Position property: https://www.mathworks.com/help/matlab/ref/uicontrol.html
I hope this helps.

Voss
Voss 2024-4-3,5:37
Default geoaxes Units are normalized (see here), which means that a Position of [100 100 500 500] places the geoaxes' lower left corner at 100 times the size of the uifigure and makes the geoaxes' size 500 times the size of the uifigure. That's why it doesn't show up when specifying the Position - it's way outside the uifigure.
To make the Position [100 100 500 500] pixels, set its Units to pixels before setting the position, e.g.:
gx = geoaxes('Parent',fig,'Units','pixels','Position',[100 100 500 500]);
It doesn't need to be in one call like that, but Units does need to be set before Position for it to work right.
(If you want the geoaxes to remain at the size 500x500 pixels, you'll also need to specify that the uifigure has its 'AutoResizeChildren' property set to 'off', if you are not already doing that.)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by