Flipping the x labels in a plot

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

 採用された回答

Star Strider
Star Strider 2019 年 6 月 28 日

1 投票

Try this:
x = linspace(0, 1000, 20);
y = exp(0.01*x);
figure
plot(x, y)
grid
title('Original')
figure
plot(x, y)
grid
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 件のコメント

Hans123
Hans123 2019 年 6 月 28 日
works perfectly! Thanks Star Strider, much appreciated
Star Strider
Star Strider 2019 年 6 月 28 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2019 年 6 月 28 日

コメント済み:

2019 年 6 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by