File Exchange

image thumbnail

Align axes labels in 3D plot

version 1.3.0.0 (2.21 KB) by Matthew Arthington
Align the x, y and z labels of the current axes with the x, y and z axes for 3D plots.

41 Downloads

Updated 30 Jan 2012

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

If the current axes have been rotated away from the X-Y view, this function will calculate the angles of the current x, y and z axes with respect to horizontal. These angles are used to rotate the current x, y and z axes labels to align them with their respective directions.

This only works for equal sized axes (axis equal) and orthographic projection.

Cite As

Matthew Arthington (2020). Align axes labels in 3D plot (https://www.mathworks.com/matlabcentral/fileexchange/27450-align-axes-labels-in-3d-plot), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)

Eric LePage

Apology. The problem is semantics. "Align" is a bad word because it creates the high expectation that the text will always lie parallel to the axis at whichever angle the axis occurs. The labels sort-of follow the start of the axis, and are kept upright in order that the text itself is not slanted. In my case I have been using a larger font for publication purposes, and the position of the x and y labels are inconsistently dissimilar in relation to the axes. Reasonable effort therefore. (This is the kind of capability which the user has a right to expect that Mathworks would have done properly from the outset).

Eric LePage

Does not work. There needs to be better description of prerequisite conditions. e.g. most generally for 3D plots the axes will be different parameters with different ranges. If the only circumstances for which this works is that the parameters are the same and plotted isometrically, then the routine is not going to be much use for most users. Also the callback needs to work with "rotate3D on" so that they stay aligned whichever way the plot is dragged. If that is what is intended, it needs more work. (Incidentally in the example plot above does not seem to be axis equal).

Does not work

Haibo Huang

Thank you for the try, but this function is not working. My axis are x=[0:0.2:0.8] and y=[6:1:10]. Then, both axis have 5 elements (equal). When I run nothing happen.

hypmfrcl

Do not work. Fails when axis not equal.

Prefect. Thanks!

Very useful function!

@jasongrig

"Tools For Axis Label Alignment In 3 D Plot" was inspired by this function. Please look at that submission to see if it can do what you need.

jasongrig

Hi, this does work with "axis equal" on. Any idea on how to make it work with the z axis set to automatic?

Fantastic program. It works!

Maria

that was perfect...just has a typing mistake.... instead of axis equal you have written axes equal....thnx

@Jveer

Yes, it does, and I've updated it so that it also works with Camera Roll too. Hope this helps.

Jveer

does this work if you rotate using orbit camera from cameratoolbar?

From the author: The labels should appear in the same place for the same view, but Matlab decides where that place is according to the current spacing.

I've looked into making this work without "axis equal" having been called (equal sized axes) and I'm stumped as to how to figure out the stretch of the plotted axes when they're not equal. Any help would be appreciated.

Rob Campbell

Useful. The only problem is that if you rotate and re-align a few times then it's possible for the labels to drift away from the centre of the axes. It would be nice if the label were re-centred as well as aligned.

Updates

1.3.0.0

Fixed typos in help and warning. Updated help with examples including its use as a callback after each rotate3d event.

1.2.0.0

Updated to allow Camera Roll to be used and still work out the angles correctly, i.e. allow a change in CameraUpVector axes property. The z axis label will now be rotated too, to align it with its axis direction if the camera has been rolled.

1.1.0.0

Added the conditions under which the function correctly works.

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

Inspired: phymhan/matlab-axis-label-alignment