Skip to content

Commit 1625557

Browse files
committed
BUG: subplots with layout kw may show unnecessary warning
1 parent 0efd4b3 commit 1625557

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/whatsnew/v0.16.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Bug Fixes
237237

238238

239239
- Bug in boxplot, scatter and hexbin plot may show an unnecessary warning (:issue:`8877`)
240+
- Bug in subplot with ``layout`` kw may show unnecessary warning (:issue:`9464`)
240241

241242

242243

pandas/tests/test_graphics.py

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import itertools
66
import os
77
import string
8+
import warnings
89
from distutils.version import LooseVersion
910

1011
from datetime import datetime, date
@@ -1245,6 +1246,7 @@ def test_subplots_timeseries(self):
12451246
self._check_visible(ax.get_yticklabels())
12461247
self._check_ticks_props(ax, xlabelsize=7, xrot=45, ylabelsize=7)
12471248

1249+
@slow
12481250
def test_subplots_layout(self):
12491251
# GH 6667
12501252
df = DataFrame(np.random.rand(10, 3),
@@ -1290,6 +1292,21 @@ def test_subplots_layout(self):
12901292
self._check_axes_shape(axes, axes_num=1, layout=(3, 3))
12911293
self.assertEqual(axes.shape, (3, 3))
12921294

1295+
@slow
1296+
def test_subplots_warnings(self):
1297+
# GH 9464
1298+
warnings.simplefilter('error')
1299+
try:
1300+
df = DataFrame(np.random.randn(100, 4))
1301+
df.plot(subplots=True, layout=(3, 2))
1302+
1303+
df = DataFrame(np.random.randn(100, 4),
1304+
index=date_range('1/1/2000', periods=100))
1305+
df.plot(subplots=True, layout=(3, 2))
1306+
except Warning as w:
1307+
self.fail(w)
1308+
warnings.simplefilter('default')
1309+
12931310
@slow
12941311
def test_subplots_multiple_axes(self):
12951312
# GH 5353, 6970, GH 7069

pandas/tools/plotting.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,8 @@ def _make_legend(self):
11261126

11271127
elif self.subplots and self.legend:
11281128
for ax in self.axes:
1129-
ax.legend(loc='best')
1129+
if ax.get_visible():
1130+
ax.legend(loc='best')
11301131

11311132
def _get_ax_legend(self, ax):
11321133
leg = ax.get_legend()

0 commit comments

Comments
 (0)