yyaxis: how to get matching ticks on left/right y-axis?

조회 수: 67 (최근 30일)
JarryG
JarryG 2020년 3월 10일
편집: Andres 2022년 6월 27일
In my script I have been using:
plotyy(x,y1,x,y2)
But now editor says "plotyy is not recommended, use yyaxis instead". Not a big issue, so I changed my script, but now left and right vertical axis have different number of ticks (in my case 6 ticks on the left y-axis, 7 ticks on the right y-axis).
So with "grid on" horizontal lines are properly connected to ticks of the left y-axis, but not to the ticks of the right y-axis. How can I fix this? With "plotyy" I always used "YLimits auto" and "YTickMode auto" and never had such problem...

답변 (2개)

Andres
Andres 2022년 6월 25일
편집: Andres 2022년 6월 27일
More than I like (major) grid lines in plots I hate grid lines that miss ticks on an axis or that connect to ticks at bad values – an insult to the eyes ;-)
You may have a look at my file exchange submission yyaxis tools that contains the function yytick to automatically align the ticks of both y-axes.

Ameer Hamza
Ameer Hamza 2020년 3월 10일
편집: Ameer Hamza 2020년 3월 10일
You can link the limits of both axes so that they remain the same
fig = figure();
ax = axes();
yyaxis right
linkprop(ax.YAxis, 'Limits');
plot(...); % plot on any of the axes
  댓글 수: 2
JarryG
JarryG 2020년 3월 10일
Yes I can, but it does not look well if curve1 has values 0-7 and curve2 0-600...
Ameer Hamza
Ameer Hamza 2020년 3월 10일
Yes, It will happen. The other alternative is just to let the axis unlinked.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by