How to reverse x-axis in a stacked plot.

I have used the code below to plot a stacked plot,
X = [4 3 2 1];
x = X';
Y = [2 3 4 5; 3 4 5 6];
y = Y';
plot1=stackedplot(x,y)
The returned plot has a x-direction from min value to max value, how can I modify the code to make it from max to min as the X data presented?

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 22 日
編集済み: Ameer Hamza 2020 年 4 月 22 日

0 投票

stackedplot is still very limited in capabilities and does not support several features. Manipulating the appearance of X-axis is one of them. Currently, your best bet is to use subplots with few modifications to make it look like stackedplot.
X = [4 3 2 1];
x = X';
Y = [2 3 4 5; 3 4 5 6];
y = Y';
% plot1=stackedplot(x,y)
ax1 = subplot(2,1,1);
plot(x, y(:,1));
ax1.XAxis.Visible = 'off';
ax1.Position(2) = ax1.Position(2)-0.05;
ax1.XDir = 'reverse';
ax2 = subplot(2,1,2);
plot(x, y(:,2));
ax2.Position(2) = ax2.Position(2)+0.05;
ax2.XDir = 'reverse';

1 件のコメント

Zhen Liu
Zhen Liu 2020 年 5 月 13 日
Thanks for your answer. It works way.

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

その他の回答 (2 件)

Adam Danz
Adam Danz 2020 年 11 月 19 日
編集済み: Adam Danz 2020 年 11 月 24 日

1 投票

You can get the axis handles in stackedplot using the undocumented NodeChildren property.
x = [4 3 2 1];
y = [2 3 4 5; 3 4 5 6]';
h = stackedplot(x,y);
set(findobj(h.NodeChildren,'Type','Axes'),'XDir','reverse')
Fangjun Jiang
Fangjun Jiang 2020 年 4 月 22 日

0 投票

This is interesting. I wonder if this meets your need.
%%
x=1:4;
y=rand(size(x));
plot(y,x);
xlabel('y');
ylabel('x');
axis ij
view(90,-90);

1 件のコメント

Adam Danz
Adam Danz 2020 年 11 月 19 日
Error using view (line 63)
Using view with stackedplot is not supported.

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

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

タグ

質問済み:

2020 年 4 月 22 日

編集済み:

2020 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by