Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rc grid parameter inconsistency #2110

Merged
merged 2 commits into from Aug 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -419,6 +419,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 @@ -577,6 +578,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 @@ -1664,6 +1664,29 @@ def make_patch_spines_invisible(ax):
host.tick_params(axis='x', **tkw)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 convention: there should be two lines between functions.


@cleanup
def test_rcparam_grid_minor():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a @cleanup decorator to this function, please?

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


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 convention: two lines (and only two) between functions. You can install the flake8 plugin in vim so that it tells you straight away if your code is pep8 or not.

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