pixelofaxis

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - User interface
Introduced first in SolidGeometry 3.4, Creation date: 2017-02-23, Last change: 2025-08-19

returns the axis position of the current axis in the figure

Description

This function is useful for placing uicontrol objects relative to subplots such as in VMplot

See Also: , pixelpositionofP , select3d

Example Illustration

 missing image of pixelofaxis

Syntax

sp=pixelofaxis

Output Parameter

sp: [left bottom size-x size-y]

Examples


subplot(2,2,4);
sp=pixelofaxis
uicontrol('Style', 'popup','String', {'R-Joint','P-Joint','G-Joint'},'Position', sp)




Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, pixelofaxis, calculates the pixel position of the current axis within a figure in MATLAB. It is particularly useful for placing UI control objects relative to subplots.

Input Parameters

The function does not take any input parameters.

Output Results

Algorithm Steps

  1. Retrieve the position of the current figure using get(gcf,'Position') and store it in fs.
  2. Retrieve the position of the current axis using get(gca,'Position') and store it in ss.
  3. Extract the width (dx) and height (dy) of the figure from fs.
  4. Calculate the pixel position of the axis within the figure and store it in sp. This is done by scaling the axis position ss with the figure dimensions dx and dy.
  5. Retrieve the current axis limits using axis and calculate the range in the x (dx) and y (dy) directions.
  6. Calculate the scaling factors fx and fy for the x and y directions, respectively, by dividing the axis size in pixels by the axis range.
  7. Calculate the offset x0 and y0 for the axis in the x and y directions, respectively, by dividing the negative pixel position by the scaling factors.
  8. Store the offsets in p0 and the scaling factors in ff.

Example Usage

The function can be used to position a UI control relative to a subplot:

subplot(2,2,4);
sp = pixelofaxis;
uicontrol('Style', 'popup', 'String', {'R-Joint', 'P-Joint', 'G-Joint'}, 'Position', sp);
Algorithm explaination created using ChatGPT on 2025-08-19 00:07. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21