How to keep yticklabels intact after reversing the Y-axis

4 ビュー (過去 30 日間)
KarolN
KarolN 2021 年 12 月 5 日
コメント済み: Star Strider 2021 年 12 月 5 日
I reversed y-direction in a chart, but I would like my yticklabels stay same as were, ie. 80 at the top and 0 at bottom. How do I solve it?
I tried to define them manually but to no avail
yticklabels([0:10:80])
set(gca,'ydir','reverse')
  1 件のコメント
DGM
DGM 2021 年 12 月 5 日
What's wrong with just flipping your data?
y = 80-y;
?

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

採用された回答

Star Strider
Star Strider 2021 年 12 月 5 日
Just change the labels —
x = linspace(0, 100);
y = [20:20:80].'*exp(-(x-50).^2/75);
figure
plot(x, y)
grid
title('Original')
figure
plot(x, y)
grid
Ax = gca;
yt = Ax.YTick;
Ax.YDir = 'reverse';
Ax.YTickLabel = string(flip(yt));
title('Flipped Y-Axis With Retained Original Y-Axis Labels')
.
  2 件のコメント
KarolN
KarolN 2021 年 12 月 5 日
Thanks!
Star Strider
Star Strider 2021 年 12 月 5 日
As always, my pleasure!
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by