バージョン (41.7 KB) 作成者: Kelly Kearney
Returns the position of a plotted axis region
ダウンロード: 5.2K
更新 2021/9/23

plotboxpos.m: Plot box (visible) position

Author: Kelly Kearney View plotboxpos on File Exchange

This repository includes the code for the plotboxpos.m Matlab function.

This function returns the position of the plotted region of an axis, which may differ from the actual axis position, depending on the axis limits, data aspect ratio, and plot box aspect ratio. The position is returned in the same units as the those used to define the axis itself. This function can only be used for a 2D plot.


  • Getting started
  • Syntax
  • Examples
  • Contributions

Getting started


This function requires Matlab R14 or later.

Downloading and installation

This code can be downloaded from Github or the MatlabCentral File Exchange. The File Exchange entry is updated daily from the GitHub repository.

Matlab Search Path

The following folders need to be added to your Matlab Search path (via addpath, pathtool, etc.):



pos = plotboxpos(h) returns the 1 x 4 position vector pos for the axis with handle h. The units of pos will match those of the axis' parent object (typically the figure).


We start by plotting a circle, changing the axis aspect ratio to be 1:1 and the axis limits to be tight to the data. = axes;
h.ex = rectangle('position', [0 0 1 1], 'curvature', [1 1]);
axis tight equal;
box on;

The axis 'Position' property still corresponds to the full potential axis space, discounting the axis modifications we just made.

pos1 = get(, 'position');
annotation('rectangle', pos1, 'edgecolor', 'b', 'linestyle', '--');

The plotboxpos function returns the position the axis is actually using with its current axis ratio settings;

pos2 = plotboxpos(;
annotation('rectangle', pos2, 'edgecolor', 'r', 'linestyle', '-.');


Community contributions to this package are welcome!

To report bugs, please submit an issue on GitHub and include:

  • your operating system
  • your version of Matlab and all relevant toolboxes (type ver at the Matlab command line to get this info)
  • code/data to reproduce the error or buggy behavior, and the full text of any error messages received

Please also feel free to submit enhancement requests, or to send pull requests (via GitHub) for bug fixes or new features.

I do monitor the MatlabCentral FileExchange entry for any issues raised in the comments, but would prefer to track issues on GitHub.

Published with MATLAB R2016b


Kelly Kearney (2024). plotboxpos (, GitHub. 取得済み .

MATLAB リリースの互換性
作成: R14SP2
Windows macOS Linux
Help Center および MATLAB AnswersAspect Ratios and Layout についてさらに検索

ヒントを与えたファイル: offsetAxes(ax), label, Antarctic Mapping Tools

Community Treasure Hunt

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

Start Hunting!


GitHub の既定のブランチを使用するバージョンはダウンロードできません

バージョン 公開済み リリース ノート

linked GitHub readme

Updated description to match the one on GitHub.
Linked to GitHub repository

- verified for R2014b graphics

Now defaults to current axis if no input provided. Also updated example image to a simpler one.

Small rewrite to remove dependency on external functions

Fixed incorrect behavior when aspect ratios set to 'auto', and some bugs regarding plot box aspect ratio.

この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。