MATLAB: How to show the major grid lines as solid and the minor grid lines as dotted

dwhhggridslinelinestyleMATLAB

I would like to set the major grid lines to have a solid linestyle, and the minor gridlines to have a dashed/dotted linestyle.

Best Answer

  • In order to change the style of the major gridlines, use the SET command as in the following example:
    plot(1:10)
    grid
    set(gca,'gridlinestyle','-')
    grid minor
    This example will draw the major grid lines and change their style to solid (using the SET command for the axes GridLineStyle property) and then draw the minor grid lines without changing their linestyle.