Skip to content

Commit 711c63a

Browse files
committed
Axes.grid controls minor and/or major lines; axis.grid allows 'both'
svn path=/trunk/matplotlib/; revision=8402
1 parent 52dc711 commit 711c63a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2010-06-09 Allow Axes.grid to control minor gridlines; allow
2+
Axes.grid and Axis.grid to control major and minor
3+
gridlines in the same method call. - EF
4+
15
2010-06-06 Change the way we do split/dividend adjustments in
26
finance.py to handle dividends and fix the zero division bug reported
37
in sf bug 2949906. Note that volume is not adjusted

lib/matplotlib/axes.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,18 +1957,21 @@ def set_axisbelow(self, b):
19571957
self._axisbelow = b
19581958

19591959
@docstring.dedent_interpd
1960-
def grid(self, b=None, **kwargs):
1960+
def grid(self, b=None, which='major', **kwargs):
19611961
"""
19621962
call signature::
19631963
1964-
grid(self, b=None, **kwargs)
1964+
grid(self, b=None, which='major', **kwargs)
19651965
19661966
Set the axes grids on or off; *b* is a boolean. (For Matlab
19671967
compatibility, *b* may also be a string, 'on' or 'off'.)
19681968
19691969
If *b* is *None* and ``len(kwargs)==0``, toggle the grid state. If
19701970
*kwargs* are supplied, it is assumed that you want a grid and *b*
1971-
is thus set to *True*
1971+
is thus set to *True*.
1972+
1973+
*which* can be 'major' (default), 'minor', or 'both' to control
1974+
whether major tick grids, minor tick grids, or both are affected.
19721975
19731976
*kawrgs* are used to set the grid line properties, eg::
19741977
@@ -1981,8 +1984,8 @@ def grid(self, b=None, **kwargs):
19811984
if len(kwargs):
19821985
b = True
19831986
b = _string_to_bool(b)
1984-
self.xaxis.grid(b, **kwargs)
1985-
self.yaxis.grid(b, **kwargs)
1987+
self.xaxis.grid(b, which=which, **kwargs)
1988+
self.yaxis.grid(b, which=which, **kwargs)
19861989

19871990
def ticklabel_format(self, **kwargs):
19881991
"""

lib/matplotlib/axis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ def get_minor_ticks(self, numticks=None):
10021002
def grid(self, b=None, which='major', **kwargs):
10031003
"""
10041004
Set the axis grid on or off; b is a boolean. Use *which* =
1005-
'major' | 'minor' to set the grid for major or minor ticks.
1005+
'major' | 'minor' | 'both' to set the grid for major or minor ticks.
10061006
10071007
If *b* is *None* and len(kwargs)==0, toggle the grid state. If
10081008
*kwargs* are supplied, it is assumed you want the grid on and *b*
@@ -1013,14 +1013,15 @@ def grid(self, b=None, which='major', **kwargs):
10131013
xax.grid(color='r', linestyle='-', linewidth=2)
10141014
"""
10151015
if len(kwargs): b = True
1016-
if which.lower().find('minor')>=0:
1016+
which = which.lower()
1017+
if which in ['minor', 'both']:
10171018
if b is None: self._gridOnMinor = not self._gridOnMinor
10181019
else: self._gridOnMinor = b
10191020
for tick in self.minorTicks: # don't use get_ticks here!
10201021
if tick is None: continue
10211022
tick.gridOn = self._gridOnMinor
10221023
if len(kwargs): artist.setp(tick.gridline,**kwargs)
1023-
if which.lower().find('major')>=0:
1024+
if which in ['major', 'both']:
10241025
if b is None: self._gridOnMajor = not self._gridOnMajor
10251026
else: self._gridOnMajor = b
10261027
for tick in self.majorTicks: # don't use get_ticks here!

0 commit comments

Comments
 (0)