Skip to content

Commit

Permalink
Merge pull request #10212 from artemyk/plotting_grid_fix
Browse files Browse the repository at this point in the history
BUG: plot doesnt default to matplotlib axes.grid setting (#9792)
  • Loading branch information
Tom Augspurger committed May 27, 2015
2 parents f306883 + 5df497e commit 1d87174
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ Bug Fixes
- Bug in ``DatetimeIndex`` and ``TimedeltaIndex`` names are lost after timedelta arithmetics ( :issue:`9926`)

- Bug in `Series.plot(label="LABEL")` not correctly setting the label (:issue:`10119`)
- Bug in `plot` not defaulting to matplotlib `axes.grid` setting (:issue:`9792`)


44 changes: 44 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,38 @@ def _check_box_return_type(self, returned, return_type, expected_keys=None,
else:
raise AssertionError

def _check_grid_settings(self, obj, kinds, kws={}):
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792

import matplotlib as mpl

def is_grid_on():
xoff = all(not g.gridOn for g in self.plt.gca().xaxis.get_major_ticks())
yoff = all(not g.gridOn for g in self.plt.gca().yaxis.get_major_ticks())
return not(xoff and yoff)

spndx=1
for kind in kinds:
self.plt.subplot(1,4*len(kinds),spndx); spndx+=1
mpl.rc('axes',grid=False)
obj.plot(kind=kind, **kws)
self.assertFalse(is_grid_on())

self.plt.subplot(1,4*len(kinds),spndx); spndx+=1
mpl.rc('axes',grid=True)
obj.plot(kind=kind, grid=False, **kws)
self.assertFalse(is_grid_on())

if kind != 'pie':
self.plt.subplot(1,4*len(kinds),spndx); spndx+=1
mpl.rc('axes',grid=True)
obj.plot(kind=kind, **kws)
self.assertTrue(is_grid_on())

self.plt.subplot(1,4*len(kinds),spndx); spndx+=1
mpl.rc('axes',grid=False)
obj.plot(kind=kind, grid=True, **kws)
self.assertTrue(is_grid_on())

@tm.mplskip
class TestSeriesPlots(TestPlotBase):
Expand Down Expand Up @@ -1108,6 +1140,12 @@ def test_table(self):
_check_plot_works(self.series.plot, table=True)
_check_plot_works(self.series.plot, table=self.series)

@slow
def test_series_grid_settings(self):
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
self._check_grid_settings(Series([1,2,3]),
plotting._series_kinds + plotting._common_kinds)


@tm.mplskip
class TestDataFramePlots(TestPlotBase):
Expand Down Expand Up @@ -3426,6 +3464,12 @@ def test_sharey_and_ax(self):
"y label is invisible but shouldn't")


@slow
def test_df_grid_settings(self):
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
self._check_grid_settings(DataFrame({'a':[1,2,3],'b':[2,3,4]}),
plotting._dataframe_kinds, kws={'x':'a','y':'b'})


@tm.mplskip
class TestDataFrameGroupByPlots(TestPlotBase):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
self.rot = self._default_rot

if grid is None:
grid = False if secondary_y else True
grid = False if secondary_y else self.plt.rcParams['axes.grid']

self.grid = grid
self.legend = legend
Expand Down

0 comments on commit 1d87174

Please sign in to comment.