anyway to add grid based on right yyaxis

Hi:
is there anyway to add grid based on right yyaxis instead of the left one?
Thanks!
Yu

 Accepted Answer

madhan ravi
madhan ravi on 19 Dec 2018
Edited: madhan ravi on 19 Dec 2018
As Cris LaPierre as already stated the precise algorithm , what you can do is you can just swap the yyaxis right to left and vice versa thereby satisfying your needs .
Or try this example using plotyy() and then follow it to your case:
[AX,H1,H2] =plotyy((1:10),(1:10),(1:10),(1:10).^2);
AX(1).YTick=1:10; % make sure both the ticks have the same number of points to align them equally
AX(2).YTick=0:10:100;
AX(1).XGrid='on';
AX(2).XGrid='on';
AX(2).YGrid='on'; % grab the second axis handle and add grid lines to it
% AX(1).YMinorGrid='off';
AX(2).LineWidth=2;

6 Comments

Thanks for your reply. I have address the issue by swap the right-left y-axis.
Bests,
Yu
Anytime :) , if my answer worked make sure to accept the answer.
Yu Li
Yu Li on 19 Dec 2018
Edited: Yu Li on 19 Dec 2018
Yes, your answer works to solve my specific problem. However, it does not provide solution to this topic: 'anyway to add grid based on right yyaxis', so I can not accept it. I'm sorry. I really appreciate your answer.
Bests,
Yu
madhan ravi
madhan ravi on 19 Dec 2018
Edited: madhan ravi on 19 Dec 2018
According to the documentation it clearly states that it only works according to left yyaxis so what's the point ? Did you see my second option in the answer? It clearly shows how to add grid to the second y axis.
That function is not recommended after 2016a.
Mathworks has announced 2019 several days ago.
Thank you!
Yu
Your welcome! , hopefully the option is added in the latter version.

Sign in to comment.

More Answers (2)

It does not appear to be possible to add a grid line to the right axis when plotting using yyaxis. There are methods available in Answers if you use plotyy.
My source is the documentation page for yyaxis > Algorithms:
Grid Lines
Grid lines correspond with the tick mark locations along the left y-axis.
Well, then swap your plotting variables so that the variable you want to have aligned grid lines is on the left.
Not being a smart alec, but if you can't beat the system, then use the system.

Categories

Asked:

on 18 Dec 2018

Answered:

on 25 Oct 2022

Community Treasure Hunt

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

Start Hunting!