MATLAB: Plotyy Display Gridlines Axis

gridlines

I am using plotyy, I managed to show the grid for the function on the left using 'grid on', but how do I show the gridlines using the function on the right?

Best Answer

You can select the second axis handle for the data plotted with respect to the right y-axis. If you define an output for the plotyy function, the output variable will contain the figure axes handles in a vector. You can then use the set function to define the 'Xgrid' and 'Ygrid' states as 'on'.
For example:
% Outputs of the plotyy are the axes handles (in a vector) and each line handle
[haxes,hline1,hline2] = plotyy(t,z1,t,z2,'semilogy','plot');
% Turn the grid for the second axis on
set(haxes(2),'Xgrid','on')
set(haxes(2),'Ygrid','on')
Check out the documentation for more information on the set function: