Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b73236b

Browse files
committed
add "axis='xy'" option to grid() for independent control of each axis' grid.
modified: lib/matplotlib/axes.py modified: lib/matplotlib/pyplot.py
1 parent 4bcec9c commit b73236b

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,8 +2644,8 @@ def cla():
26442644
# This function was autogenerated by boilerplate.py. Do not edit as
26452645
# changes will be lost
26462646
@docstring.copy_dedent(Axes.grid)
2647-
def grid(b=None, which='major', **kwargs):
2648-
ret = gca().grid(b, which, **kwargs)
2647+
def grid(b=None, which='major', axis='xy', **kwargs):
2648+
ret = gca().grid(b, which, axis, **kwargs)
26492649
draw_if_interactive()
26502650
return ret
26512651

0 commit comments

Comments
 (0)