Skip to content

Commit 79bd660

Browse files
committed
Merge pull request matplotlib#2110 from Carreau/fix-rc-grid
Fix rc grid parameter inconsistency
2 parents deb9f1c + 0aae63d commit 79bd660

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def cla(self):
890890
self.collections = [] # collection.Collection instances
891891
self.containers = []
892892

893-
self.grid(self._gridOn)
893+
self.grid(self._gridOn, which=rcParams['axes.grid.which'])
894894
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
895895

896896
self.titleOffsetTrans = mtransforms.ScaledTranslation(

lib/matplotlib/axis.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, axes, loc, label,
7070
labelsize=None,
7171
labelcolor=None,
7272
zorder=None,
73-
gridOn=None, # defaults to axes.grid
73+
gridOn=None, # defaults to axes.grid depending on axes.grid.which
7474
tick1On=True,
7575
tick2On=True,
7676
label1On=True,
@@ -85,7 +85,12 @@ def __init__(self, axes, loc, label,
8585
artist.Artist.__init__(self)
8686

8787
if gridOn is None:
88-
gridOn = rcParams['axes.grid']
88+
if major and (rcParams['axes.grid.which'] in ('both','major')):
89+
gridOn = rcParams['axes.grid']
90+
elif (not major) and (rcParams['axes.grid.which'] in ('both','minor')):
91+
gridOn = rcParams['axes.grid']
92+
else :
93+
gridOn = False
8994

9095
self.set_figure(axes.figure)
9196
self.axes = axes
@@ -733,8 +738,8 @@ def cla(self):
733738
self.callbacks = cbook.CallbackRegistry()
734739

735740
# whether the grids are on
736-
self._gridOnMajor = rcParams['axes.grid']
737-
self._gridOnMinor = False
741+
self._gridOnMajor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','major'))
742+
self._gridOnMinor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','minor'))
738743

739744
self.label.set_text('')
740745
self._set_artist_props(self.label)

lib/matplotlib/rcsetup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def validate_hinting(s):
414414
validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
415415
['png', 'jpeg', 'tiff', 'raw', 'rgba'])
416416

417+
validate_axis_locator = ValidateInStrings('major', ['minor','both','major'])
417418

418419
def validate_bbox(s):
419420
if type(s) is str:
@@ -572,6 +573,10 @@ def __call__(self, s):
572573
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
573574
# axes title
574575
'axes.grid': [False, validate_bool], # display grid or not
576+
'axes.grid.which': ['major', validate_axis_locator], # set wether the gid are by
577+
# default draw on 'major'
578+
# 'minor' or 'both' kind of
579+
# axis locator
575580
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
576581
# x any y labels
577582
'axes.labelweight': ['normal', str], # fontsize of the x any y labels

lib/matplotlib/tests/test_axes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,29 @@ def make_patch_spines_invisible(ax):
16661666
host.tick_params(axis='x', **tkw)
16671667

16681668

1669+
@cleanup
1670+
def test_rcparam_grid_minor():
1671+
orig_grid = matplotlib.rcParams['axes.grid']
1672+
orig_locator = matplotlib.rcParams['axes.grid.which']
1673+
1674+
matplotlib.rcParams['axes.grid'] = True
1675+
1676+
values = (
1677+
(('both'), (True, True)),
1678+
(('major'), (True, False)),
1679+
(('minor'), (False, True))
1680+
)
1681+
1682+
for locator, result in values:
1683+
matplotlib.rcParams['axes.grid.which'] = locator
1684+
fig = plt.figure()
1685+
ax = fig.add_subplot(1, 1, 1)
1686+
assert((ax.xaxis._gridOnMajor, ax.xaxis._gridOnMinor) == result)
1687+
1688+
matplotlib.rcParams['axes.grid'] = orig_grid
1689+
matplotlib.rcParams['axes.grid.which'] = orig_locator
1690+
1691+
16691692
@cleanup
16701693
def test_vline_limit():
16711694
fig = plt.figure()

0 commit comments

Comments
 (0)