Plot with the same Y-axis on both sides
70 ビュー (過去 30 日間)
古いコメントを表示
Hi guys,
I have a graph with a very long x-axis. It would be good if I could show the same Y-axis on both sides. I have not been able to find an answer under yyaxis. There the right axis always has a different scaling. Is there a solution for this at all?
Thank you very much!
0 件のコメント
採用された回答
Star Strider
2023 年 4 月 7 日
Duplicating the y-axis on the right side is not an option, however writing the tick labels on the right axis definitely is.
Try something like this —
x = 1:10;
y = randn(size(x));
figure
plot(x, y)
grid
Ax = gca;
ytix = Ax.YTick;
ytl = Ax.YTickLabel;
text(ones(size(ytix))*max(xlim)+0.02*diff(xlim), ytix, ytl, 'Horiz','left', 'Vert','middle')
This should adapt to different plots without changing it much. Make appropriate changes to get the result you want.
.
0 件のコメント
その他の回答 (1 件)
Adam Danz
2023 年 4 月 7 日
編集済み: Adam Danz
2023 年 7 月 14 日
You can use yyaxis but you need to link the left and right y rulers so when one changes, the other updates. This comes in handy when zooming or panning or adding data to the axes.
clf
ax = axes;
yyaxis(ax,'right')
yyaxis(ax,'left')
linkprop([ax.XAxis; ax.YAxis],'color')
linkprop([ax.YAxis(1), ax.YAxis(2)],{'Limits','TickValues'});
box(ax,'on')
plot(ax, rand(1,6))
grid(ax,'on')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!