フィルターのクリア

How to make all but one axis visible on plot

47 ビュー (過去 30 日間)
Eileen Lukens
Eileen Lukens 2021 年 6 月 9 日
編集済み: Adam Danz 2023 年 7 月 14 日
I want to make my plot with both Y axes visible, the bottom X axes visibile, but have the top X-axis invisible. I know you can set the 'XColor' to 'none' and both the top and bottom axes will become invisible. How do I make it so everything but the top axes is visible? Included below is what I would like to achieve. I'm doing this in a subplotting routine so I'm hoping to avoid anything that is hardcoded such as a white rectangle positioned to hide the top axis. Thanks!

採用された回答

Adam Danz
Adam Danz 2021 年 6 月 10 日
編集済み: Adam Danz 2023 年 7 月 14 日
Another simple way is to use yyaxis to create two y axes but you'll ignore the right-side axes.
Also see this answer to turn off the right axis while keeping visible the other 3 axes.
clf
ax = axes;
yyaxis(ax,'right')
ax.YTickLabels = '';
yyaxis(ax,'left') % * see footnote [1]
linkprop([ax.XAxis; ax.YAxis],'color'); % set axes colors to match
linkprop([ax.YAxis(1), ax.YAxis(2)],{'Limits','TickValues'}); % * see footnote [2]
box(ax,'off') % see footnote [3]
[1] It's important the you run yyaxis(ax,'left') after making changes to the right-side so that your plotting is all assigned to the left axes.
[2] This line links the y limits and ticks for the 2 y axes; otherwise you could remove the tick on the right using ax.YTick = [];
[3] You may need to call this line again after plotting or hold your axes using hold(ax,'on')
  1 件のコメント
Eileen Lukens
Eileen Lukens 2021 年 6 月 10 日
Thank you! That did the trick!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by