필터 지우기
필터 지우기

How can I rotate the axis tick labels in 2-D and 3-D?

조회 수: 10 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2013년 10월 18일
편집: MathWorks Support Team 2023년 5월 19일
I would like to rotate the axis tick labels in 2-D and 3-D.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 5월 19일
편집: MathWorks Support Team 2023년 5월 19일
For MATLAB releases before R2014b, below is an example that demonstrates how to rotate the X-tick labels in MATLAB :
% Create some data:
X = 1:12;
Y = rand(1,12);
% Generate a plot
bar(X,Y);
% Set the tick locations and remove the labels
set(gca,'XTick',1:12,'XTickLabel','')
% Define the labels
lab = [{'January'};{'February'};{'March'};{'April'};{'May'};{'June'};...
{'July'};{'August'};{'September'};{'October'};...
{'November'};{'December'}];
% Estimate the location of the labels based on the position
% of the xlabel
hx = get(gca,'XLabel'); % Handle to xlabel
set(hx,'Units','data');
pos = get(hx,'Position');
y = pos(2);
% Place the new labels
for i = 1:size(lab,1)
t(i) = text(X(i),y,lab(i,:));
end
set(t,'Rotation',90,'HorizontalAlignment','right')
Following is a simple example of how to rotate an x-label in 3-D:
view(3)
xlabel('Hello');
h = get(gca,'xlabel');
set(h,'Rotation',20)
Alternatively, you can use this user created File Exchange submission that can perform the same task:
Please note that the above File Exchange file was not authored by MathWorks. Any questions regarding this file should be directed to the contributing author of that file.
NOTE: If you are working under the MS Windows version of MATLAB, you will need to make sure that you are using a Truetype font in your text objects. Truetype are the only fonts which can be rotated correctly on the screen and on printouts.
  댓글 수: 1
daniel
daniel 2015년 2월 4일
I think you are confusing "xlabel" with "XTickLabel" I believe the question is regarding the rotation of XTickLabels and not the Xlabel itself. I too am searching for a solution regarding the rotaion of XTickLabels but have yet to find one.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

daniel
daniel 2015년 2월 12일
if you have 2014b you can do this:
ax = gca;
ax.XTickLabelRotation = -45;

Alexey
Alexey 2016년 1월 6일
편집: MathWorks Support Team 2021년 11월 4일
or (I think starting with 2014) you can just do
ax.XTickLabelRotation=45;
as per docs

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by