Is it possible to add a secondary y axis while using the stackedplot function?
14 ビュー (過去 30 日間)
古いコメントを表示
Is it possible to add a secondary y axis while using the stackedplot function? I have some overlayed data in my stackedplot and I would like to add a secondary y axis for some of the individual plots. Is this possible?
0 件のコメント
採用された回答
Star Strider
2025 年 7 月 28 日
Apparently not.
Any provision for creating a second y-axis is apparently not available, even when attempting to 'force' it (that can occasionally work with undocumented properties, or at least has in the past). However it is possible to plot two variables on one stackedplot axis.
x = linspace(0, 10, 250).';
ym = sin(x*[1 5 9]*2*pi/10);
T1 = array2table([x ym], VariableNames={'x','y1','y2','y3'})
figure
stackedplot(T1, {{'y2','y3'}, 'y1'} )
Ax = gca;
get(Ax)
Ax1 = Ax.AxesProperties(1)
% Ax1.YAxis(2).YAxisLocation = 'right'
figure
tiledlayout(2,1)
nexttile
yyaxis left
plot(T1.x, T1.y1, DisplayName='y_1')
ylabel('y_1')
yyaxis right
plot(T1.x, T1.y2*2, DisplayName = 'y_2')
grid
ylabel('y_2')
legend(Location='best')
nexttile
plot(T1.x, T1.y3)
grid
xlabel('x')
ylabel('y_3')
.
2 件のコメント
Star Strider
2025 年 7 月 28 日
That approach using tiledlayout is the version I illustrated here. It is possible to change its appearance, however tiledlayout is resistant to some manipulations that subplot provides.
This is likely as close as you can get with tiledlayout --
x = linspace(0, 10, 250).';
ym = sin(x*[1 5 9]*2*pi/10);
T1 = array2table([x ym], VariableNames={'x','y1','y2','y3'})
figure
tiledlayout(2,1, TileSpacing='none')
nexttile
yyaxis left
plot(T1.x, T1.y1, DisplayName='y_1')
ylabel('y_1')
Axl = gca;
Axl.XAxis.Color = 'none';
yyaxis right
plot(T1.x, T1.y2*2, DisplayName = 'y_2')
grid
ylabel('y_2')
legend(Location='best')
nexttile
plot(T1.x, T1.y3)
grid
xlabel('x')
ylabel('y_3')
The subplot funciton may offer more options, particularly with respect to the Innerposition and OuterPosition properties (that aren't available in tiledlayout). Much depends on what you want to do.
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


