Is it possible to use yticks only on one side?

54 ビュー (過去 30 日間)
Mr M.
Mr M. 2018 年 10 月 5 日
コメント済み: jonas 2018 年 10 月 5 日
Is it possible to use yticks only on one side? How to set?
  5 件のコメント
Mr M.
Mr M. 2018 年 10 月 5 日
simple code: imagesc(rand(100)), and you have ticks on all sides: left,right,top, bottom. How to remove yticks from right, and xticks from top?
Adam
Adam 2018 年 10 月 5 日
I can't actually see any way to turn them off using sensible functionality. For the y ticks specifically you can use an ugly hack e.g.:
figure; imagesc( magic(25) )
yyaxis right
set( gca, 'YTick', [] )
set( gca, 'YColor', 'k' )
though I don't know a way to do it for the x axis and the above is horrible code. yyaxis is an ugly function since it gives no possibility to actually return the axis handle and instead just changes what is the current axes.

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

採用された回答

jonas
jonas 2018 年 10 月 5 日
編集済み: jonas 2018 年 10 月 5 日
The yticks appear on both sides due to the box being 'on', so to say. Remove them by
box off
This will of course also remove the frame, so here is a bonus hacky solution for retaining the frame
imagesc(rand(100))
box off
ax=gca;
axes('position',ax.Position,'box','on','ytick',[],'xtick',[],'color','none')
  2 件のコメント
Adam
Adam 2018 年 10 月 5 日
Be careful with using 2nd axes though. You will lose the ability to zoom, pan, use the data cursor functionality etc, unless you hack around with it still further :( I've had to do this a few times and it's not much fun!
jonas
jonas 2018 年 10 月 5 日
Seems like this should be an option for 'boxstyle', but currently there is only one option for 2D plots. In this specific case I think the extra axes is OK, because it is just an empty frame. You can still zoom if you have the primary axes as the current axes. You'd need to set the background transparent though
ax.Color='none'
so that the second axes is visible below the primary.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by