MATLAB Answers


Flipping the x labels in a plot

Hans123 님이 질문을 제출함. 28 Jun 2019
최근 활동 Star Strider 님이 댓글을 추가함. 28 Jun 2019
This question was asked and answered many times, but I can't seem to find the correct answer to my problem.
I want to switch the order of the x labels from ascending [0 1000] to descending [1000 0] without changing the orientation of the graph
I tried
a = gca;
a.XTickLabel = flipud(a.XTickLabel);
which worked,but changed the values of my x axis from [0 1000] to [1 0].
How can I fix this.
Thanks in advance

  댓글 수: 0

로그인 to comment.


답변 수: 1

Star Strider 님의 답변 28 Jun 2019
 채택된 답변

Try this:
x = linspace(0, 1000, 20);
y = exp(0.01*x);
plot(x, y)
plot(x, y)
xt = get(gca, 'XTick');
set(gca, 'XTickLabel', fliplr(xt))
title('Flipped X')
The first figure is the original data, the second is the same, with the x-tick values reversed.

  댓글 수: 2

works perfectly! Thanks Star Strider, much appreciated
As always, my pleasure!

로그인 to comment.

Translated by