Skip to content

Commit ba895cd

Browse files
committed
Merge pull request #9464 from sinhrks/plot_warn2
BUG: subplots with layout kw may show unnecessary warning
2 parents 2d368bc + 1625557 commit ba895cd

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v0.16.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ Bug Fixes
492492

493493

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

496497

497498

pandas/tests/test_graphics.py

+16
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ def test_subplots_timeseries(self):
12461246
self._check_visible(ax.get_yticklabels())
12471247
self._check_ticks_props(ax, xlabelsize=7, xrot=45, ylabelsize=7)
12481248

1249+
@slow
12491250
def test_subplots_layout(self):
12501251
# GH 6667
12511252
df = DataFrame(np.random.rand(10, 3),
@@ -1291,6 +1292,21 @@ def test_subplots_layout(self):
12911292
self._check_axes_shape(axes, axes_num=1, layout=(3, 3))
12921293
self.assertEqual(axes.shape, (3, 3))
12931294

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+
12941310
@slow
12951311
def test_subplots_multiple_axes(self):
12961312
# 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)