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.
Matthew Arthington (2021). Align axes labels in 3D plot (https://www.mathworks.com/matlabcentral/fileexchange/27450-align-axes-labels-in-3d-plot), MATLAB Central File Exchange. Retrieved .
Work well. Thank you.
1) Doesn't work properly with axes direction property (e.g. ax.YDir = ax.YAxis.Direction) set to 'reverse' instead of default 'normal'
2) Labels can overlap with axis ticks (z axis). Need more spacing. Workaround is to make the ticks shorter.
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).
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
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.
Do not work. Fails when axis not equal.
Very useful function!
"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.
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!
that was perfect...just has a typing mistake.... instead of axis equal you have written axes equal....thnx
Yes, it does, and I've updated it so that it also works with Camera Roll too. Hope this helps.
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.
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.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!