From 1625557085bcab980472248e518e4871c383834e Mon Sep 17 00:00:00 2001 From: sinhrks Date: Wed, 11 Feb 2015 19:31:27 +0900 Subject: [PATCH] BUG: subplots with layout kw may show unnecessary warning --- doc/source/whatsnew/v0.16.0.txt | 1 + pandas/tests/test_graphics.py | 17 +++++++++++++++++ pandas/tools/plotting.py | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.16.0.txt b/doc/source/whatsnew/v0.16.0.txt index 238a838cf727e..3bb035a1c757b 100644 --- a/doc/source/whatsnew/v0.16.0.txt +++ b/doc/source/whatsnew/v0.16.0.txt @@ -237,6 +237,7 @@ Bug Fixes - Bug in boxplot, scatter and hexbin plot may show an unnecessary warning (:issue:`8877`) +- Bug in subplot with ``layout`` kw may show unnecessary warning (:issue:`9464`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 4195baf4874f1..d7bec5f19c0c8 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -5,6 +5,7 @@ import itertools import os import string +import warnings from distutils.version import LooseVersion from datetime import datetime, date @@ -1245,6 +1246,7 @@ def test_subplots_timeseries(self): self._check_visible(ax.get_yticklabels()) self._check_ticks_props(ax, xlabelsize=7, xrot=45, ylabelsize=7) + @slow def test_subplots_layout(self): # GH 6667 df = DataFrame(np.random.rand(10, 3), @@ -1290,6 +1292,21 @@ def test_subplots_layout(self): self._check_axes_shape(axes, axes_num=1, layout=(3, 3)) self.assertEqual(axes.shape, (3, 3)) + @slow + def test_subplots_warnings(self): + # GH 9464 + warnings.simplefilter('error') + try: + df = DataFrame(np.random.randn(100, 4)) + df.plot(subplots=True, layout=(3, 2)) + + df = DataFrame(np.random.randn(100, 4), + index=date_range('1/1/2000', periods=100)) + df.plot(subplots=True, layout=(3, 2)) + except Warning as w: + self.fail(w) + warnings.simplefilter('default') + @slow def test_subplots_multiple_axes(self): # GH 5353, 6970, GH 7069 diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 9cb4c268dc506..cf9c890823f8f 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1126,7 +1126,8 @@ def _make_legend(self): elif self.subplots and self.legend: for ax in self.axes: - ax.legend(loc='best') + if ax.get_visible(): + ax.legend(loc='best') def _get_ax_legend(self, ax): leg = ax.get_legend()