Skip to content

Commit

Permalink
Merge pull request #2110 from Carreau/fix-rc-grid
Browse files Browse the repository at this point in the history
Fix rc grid parameter inconsistency
  • Loading branch information
dmcdougall committed Aug 18, 2013
2 parents deb9f1c + 0aae63d commit 79bd660
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Expand Up @@ -890,7 +890,7 @@ def cla(self):
self.collections = [] # collection.Collection instances
self.containers = []

self.grid(self._gridOn)
self.grid(self._gridOn, which=rcParams['axes.grid.which'])
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])

self.titleOffsetTrans = mtransforms.ScaledTranslation(
Expand Down
13 changes: 9 additions & 4 deletions lib/matplotlib/axis.py
Expand Up @@ -70,7 +70,7 @@ def __init__(self, axes, loc, label,
labelsize=None,
labelcolor=None,
zorder=None,
gridOn=None, # defaults to axes.grid
gridOn=None, # defaults to axes.grid depending on axes.grid.which
tick1On=True,
tick2On=True,
label1On=True,
Expand All @@ -85,7 +85,12 @@ def __init__(self, axes, loc, label,
artist.Artist.__init__(self)

if gridOn is None:
gridOn = rcParams['axes.grid']
if major and (rcParams['axes.grid.which'] in ('both','major')):
gridOn = rcParams['axes.grid']
elif (not major) and (rcParams['axes.grid.which'] in ('both','minor')):
gridOn = rcParams['axes.grid']
else :
gridOn = False

self.set_figure(axes.figure)
self.axes = axes
Expand Down Expand Up @@ -733,8 +738,8 @@ def cla(self):
self.callbacks = cbook.CallbackRegistry()

# whether the grids are on
self._gridOnMajor = rcParams['axes.grid']
self._gridOnMinor = False
self._gridOnMajor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','major'))
self._gridOnMinor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','minor'))

self.label.set_text('')
self._set_artist_props(self.label)
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/rcsetup.py
Expand Up @@ -414,6 +414,7 @@ def validate_hinting(s):
validate_movie_frame_fmt = ValidateInStrings('animation.frame_format',
['png', 'jpeg', 'tiff', 'raw', 'rgba'])

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

def validate_bbox(s):
if type(s) is str:
Expand Down Expand Up @@ -572,6 +573,10 @@ def __call__(self, s):
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
# axes title
'axes.grid': [False, validate_bool], # display grid or not
'axes.grid.which': ['major', validate_axis_locator], # set wether the gid are by
# default draw on 'major'
# 'minor' or 'both' kind of
# axis locator
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
# x any y labels
'axes.labelweight': ['normal', str], # fontsize of the x any y labels
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -1666,6 +1666,29 @@ def make_patch_spines_invisible(ax):
host.tick_params(axis='x', **tkw)


@cleanup
def test_rcparam_grid_minor():
orig_grid = matplotlib.rcParams['axes.grid']
orig_locator = matplotlib.rcParams['axes.grid.which']

matplotlib.rcParams['axes.grid'] = True

values = (
(('both'), (True, True)),
(('major'), (True, False)),
(('minor'), (False, True))
)

for locator, result in values:
matplotlib.rcParams['axes.grid.which'] = locator
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
assert((ax.xaxis._gridOnMajor, ax.xaxis._gridOnMinor) == result)

matplotlib.rcParams['axes.grid'] = orig_grid
matplotlib.rcParams['axes.grid.which'] = orig_locator


@cleanup
def test_vline_limit():
fig = plt.figure()
Expand Down

0 comments on commit 79bd660

Please sign in to comment.