Skip to content

BUG: plot doesnt default to matplotlib axes.grid setting (#9792) #10212

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

Merged
merged 1 commit into from
May 27, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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