@@ -2036,11 +2036,11 @@ def set_axisbelow(self, b):
20362036 self ._axisbelow = b
20372037
20382038 @docstring .dedent_interpd
2039- def grid (self , b = None , which = 'major' , ** kwargs ):
2039+ def grid (self , b = None , which = 'major' , axis = 'xy' , ** kwargs ):
20402040 """
20412041 call signature::
20422042
2043- grid(self, b=None, which='major', **kwargs)
2043+ grid(self, b=None, which='major', axis='xy', **kwargs)
20442044
20452045 Set the axes grids on or off; *b* is a boolean. (For MATLAB
20462046 compatibility, *b* may also be a string, 'on' or 'off'.)
@@ -2052,6 +2052,9 @@ def grid(self, b=None, which='major', **kwargs):
20522052 *which* can be 'major' (default), 'minor', or 'both' to control
20532053 whether major tick grids, minor tick grids, or both are affected.
20542054
2055+ *axis* can be 'xy' (default), 'x', or 'y' to control which
2056+ set of gridlines are drawn.
2057+
20552058 *kawrgs* are used to set the grid line properties, eg::
20562059
20572060 ax.grid(color='r', linestyle='-', linewidth=2)
@@ -2064,8 +2067,11 @@ def grid(self, b=None, which='major', **kwargs):
20642067 if len (kwargs ):
20652068 b = True
20662069 b = _string_to_bool (b )
2067- self .xaxis .grid (b , which = which , ** kwargs )
2068- self .yaxis .grid (b , which = which , ** kwargs )
2070+
2071+ if axis == 'x' or axis == 'xy' :
2072+ self .xaxis .grid (b , which = which , ** kwargs )
2073+ if axis == 'y' or axis == 'xy' :
2074+ self .yaxis .grid (b , which = which , ** kwargs )
20692075
20702076 def ticklabel_format (self , ** kwargs ):
20712077 """
0 commit comments