Highlights
팔로우


New in MATLAB R2021a: Auto rotation of axis tick labels

Adam Danz 2021년 5월 24일 (2021년 5월 24일에 수정됨)
최근 활동 MB답글 2022년 9월 21일

Starting in MATLAB R2021a axis tick labels will auto-rotate to avoid overlap when the user manually specifies ticks or tick labels ( release notes ). In custom visualization functions, the tick label density or tick label lengths may be variable and unknown. The new auto-rotation feature removes the burden of detecting the need to rotate manually-set labels and eliminates the need to manually rotate them.

Many properties and combinations of properties can cause tick labels to overlap if they are not rotated.

  • Length of tick labels
  • Number of tick labels
  • Interval between tick labels
  • Font size
  • Font name
  • Figure size
  • Axes size
  • Viewing angle of the axes

Demo: varying tick density and length of tick labels

These 9 axes vary by the number of x-ticks and length of x-tick-labels. MATLAB auto-rotates the labels when needed.

Demo: Changes to axis view angle and rotation

The auto-rotation feature updates the label angles as the axes change programmatically or during user interaction.

What if I don't want auto-rotation?

Auto-rotation mode is on by default for each X|Y|Z axis. When the tick label rotation angle is manually set from the X|Y|ZTickLabelRotation property of axes or by using xtickangle | ytickangle | ztickangle , auto-rotation is turned off. Auto-rotation can also be turned off by setting the X|Y|ZTickLabelRotationMode axis property to manual but it's important to also hold the axis properties so that the rotation mode does not revert to the default value, auto. If you're looking for a broader method of reverting to older behavior you can set the default label rotation mode to manual at the start of a function that produces multiple plots and then revert to the factory default rotation mode at the end of the file (consider using onCleanup).

set(groot,'defaultAxesXTickLabelRotationMode','manual')
set(groot,'defaultAxesYTickLabelRotationMode','manual')
set(groot,'defaultAxesZTickLabelRotationMode','manual')
% Revert to factory-default
set(groot,'defaultAxesXTickLabelRotationMode','remove')
set(groot,'defaultAxesYTickLabelRotationMode','remove')
set(groot,'defaultAxesZTickLabelRotationMode','remove')

A copy of this Community Highlight is attached as a live script.

MB
MB 2022년 9월 21일
I don't like such intrusion. Why do you impose rotation to axis labels by default? If some people want that, they type their commands. By convention, the text is horizontal. It seems you don't have something to do, so you decided to reinvent the wheel.
We encounter everyday helps and suggestions from the software we use like Google, Microsoft and many others, confining people to what the programmers (or algorithms) thinks it is good for them. With Microsoft, if I'm working on a confidential Word file, and somebody wants me to show him another Word file, the first file is inadvertently opened. In the Explorer, I double click on a folder or file to open it, the list of files jumps to the left. With Google, we have to be careful, because Google can show the list of all what we buy, visit, etc, and this is to help us. Our search is also limited to our search history in space and time. What a disaster.
Please do not make Matlab like that. Make tools, and people use the needed tools, do not impose to them what you think is better for them. Otherwise, we waste our time in undowing your help, like unrotating axis labels.
Best wishes.
Community Sherlock-
Community Sherlock- 2021년 10월 7일

Nice quality of life feature.

goc3
goc3 2021년 5월 24일

This is a helpful improvement!

And, thank you Adam for posting about so many of these.

Rik
Rik 2021년 5월 24일

Nice quality of life feature.