How to set grid lines to change with right y-axis, work around?

16 ビュー (過去 30 日間)
rokP
rokP 2018 年 3 月 21 日
回答済み: rokP 2018 年 3 月 22 日
I'd like to set grid lines to move with the right y-axis which I tried with the following code:
figure
plot(rand(100,1));
yyaxis right;
ax1=gca;
set(ax1,'YGrid','on')
but it doesn't work, which is also according to the document on yyaxis, section Grid lines where it says that grid lines correspond with the tick mark locations along the left y-axis.
Have tried several things, but no success. Is there any slick work around? Suggestions appreciated.

回答 (2 件)

KSSV
KSSV 2018 年 3 月 21 日
x=[1:100].';
y=randn(100,1); % some dummy data to plot to make axes w/ differing ranges
hAx=plotyy(x,y,x,sqrt(abs(y))/pi);
ylim(hAx(2),[0 1])
hAx(1).YAxis.Visible = 'off';
box on

rokP
rokP 2018 年 3 月 22 日
Thanks for the suggestion. Have tried it but doesn't work well for me. I'm using multiple subplots with several lines in each. A solution with 'plot()' and 'yyaxis right' would be preferable.

カテゴリ

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