File Exchange

image thumbnail


version (40.1 KB) by Kelly Kearney
Returns the position of a plotted axis region


Updated 02 Nov 2017

From GitHub

View Version History

View license on GitHub

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.

Cite As

Kelly Kearney (2021). plotboxpos (, GitHub. Retrieved .

Comments and Ratings (42)

Matthew Cooper

제파 양

this is the one exactly I'm looking for. thanks!

Mary Jo Brodzik

Thanks for this incredibly useful function. I spent most of yesterday tearing my hair out with an image display, that I had positioned to maintain the aspect ratio, trying to position text just below it. Your function is exactly what I need.

Jon Adsersen

Great function! Exactly what I needed!

Peter Lawrence


Shahar Grossbard

David Huynh

Dounia Mulders

Gabriel Rivera

Thank you very much, it is precisely what I needed.



Mohammad Askari


This is a very useful function. Thanks for making it available. It would be really great if you could suggest how to modify this to include xlabel, ylabel, title and and as well as colorbars in the current axis position. I succeeded in including xlabel, ylabel and title by using "TightInset" property, but i am unable to find anyway to include colorbar.

Mike Wilson

Is there any way to view the readme file for plotboxpos that does NOT require using GitHub?

Lilla Horvath

Rob Campbell

Just what I needed. Neatly coded. Thanks.

Arnaud Laurent


Pierre Morel

Kelly Kearney


As noted in the help, this function is only intended for 2D plots. The math gets much messier for 3D; if someone else wants to figure those calculations out I'd be happy to incorporate them, but I don't really have the motivation to do so myself. I've updated the description on this page to reflect this limitation.


Nice function, but it does not work for 3d plots with daspect([1 1 1]) !


Please ignore my previous comment. It DOES work with colorbar present.


This function does a great job. However, when the colorbar is present in the figure, the function returns the plotted axis region as if a colorbar doesn't exist. I was graphing a pcolor plot with the colorbar on when I discovered this.

Christopher Thissen



Nice Tool!
Saves me lot of time, thanks!


Brilliant little function. Cheers!

Chad Greene

Thank you Kelly for solving a problem I've had for months. This function is well written. You've saved me a world of headaches.

Jeremy Fyke

Works as advertised - thanks.


Marcelo Soto Thompson


Thanks so much. That's awesome!

Chethan Pandarinath

This is fantastic. Thanks.


Brian Emery

Finds the position of the axes after modifying the DataAspectRatio and PlotBoxAspectRatio. This is exactly what I need, thanks!

François Beauducel

Very useful function, thanks.
It's missing only a little test like:

if nargin < 1
h = gca;

and your function becomes perfect !
Thanks again.


Oscar Hartogensis


Kelly Kearney

Carlos, getInUnits.m is available in the File Exchange: ( Sorry for the confusion; I will update the documentation on this page to clarify this.

Carlos Moffat

Kelly, getInUnits does not exist, as far as I can tall, as a MATLAB function.

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!