Beispiel #1
0
    def test_grouped_hist(self):
        import matplotlib.pyplot as plt
        df = DataFrame(np.random.randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        axes = plotting.grouped_hist(df.A, by=df.C)
        self.assert_(len(axes.ravel()) == 4)

        plt.close('all')
        axes = df.hist(by=df.C)
        self.assert_(axes.ndim == 2)
        self.assert_(len(axes.ravel()) == 4)

        for ax in axes.ravel():
            self.assert_(len(ax.patches) > 0)

        plt.close('all')
        # make sure kwargs to hist are handled
        axes = plotting.grouped_hist(df.A, by=df.C, normed=True,
                                     cumulative=True, bins=4)

        # height of last bin (index 5) must be 1.0
        for ax in axes.ravel():
            height = ax.get_children()[5].get_height()
            self.assertAlmostEqual(height, 1.0)

        plt.close('all')
        axes = plotting.grouped_hist(df.A, by=df.C, log=True)
        # scale of y must be 'log'
        for ax in axes.ravel():
            self.assert_(ax.get_yscale() == 'log')

        plt.close('all')
        # propagate attr exception from matplotlib.Axes.hist
        self.assertRaises(AttributeError, plotting.grouped_hist, df.A,
                          by=df.C, foo='bar')
    def test_grouped_hist(self):
        import matplotlib.pyplot as plt
        df = DataFrame(np.random.randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        axes = plotting.grouped_hist(df.A, by=df.C)
        self.assertTrue(len(axes.ravel()) == 4)

        plt.close('all')
        axes = df.hist(by=df.C)
        self.assertTrue(axes.ndim == 2)
        self.assertTrue(len(axes.ravel()) == 4)

        for ax in axes.ravel():
            self.assertTrue(len(ax.patches) > 0)

        plt.close('all')
        # make sure kwargs to hist are handled
        axes = plotting.grouped_hist(df.A, by=df.C, normed=True,
                                     cumulative=True, bins=4)

        # height of last bin (index 5) must be 1.0
        for ax in axes.ravel():
            height = ax.get_children()[5].get_height()
            self.assertAlmostEqual(height, 1.0)

        plt.close('all')
        axes = plotting.grouped_hist(df.A, by=df.C, log=True)
        # scale of y must be 'log'
        for ax in axes.ravel():
            self.assertTrue(ax.get_yscale() == 'log')

        plt.close('all')
        # propagate attr exception from matplotlib.Axes.hist
        self.assertRaises(AttributeError, plotting.grouped_hist, df.A,
                          by=df.C, foo='bar')
Beispiel #3
0
    def test_grouped_hist(self):
        import matplotlib.pyplot as plt

        df = DataFrame(randn(500, 2), columns=["A", "B"])
        df["C"] = np.random.randint(0, 4, 500)
        axes = plotting.grouped_hist(df.A, by=df.C)
        self.assertEqual(len(axes.ravel()), 4)

        tm.close()
        axes = df.hist(by=df.C)
        self.assertEqual(axes.ndim, 2)
        self.assertEqual(len(axes.ravel()), 4)

        for ax in axes.ravel():
            self.assert_(len(ax.patches) > 0)

        tm.close()
        # make sure kwargs to hist are handled
        axes = plotting.grouped_hist(df.A, by=df.C, normed=True, cumulative=True, bins=4)

        # height of last bin (index 5) must be 1.0
        for ax in axes.ravel():
            height = ax.get_children()[5].get_height()
            self.assertAlmostEqual(height, 1.0)

        tm.close()
        axes = plotting.grouped_hist(df.A, by=df.C, log=True)
        # scale of y must be 'log'
        for ax in axes.ravel():
            self.assertEqual(ax.get_yscale(), "log")

        tm.close()
        # propagate attr exception from matplotlib.Axes.hist
        with tm.assertRaises(AttributeError):
            plotting.grouped_hist(df.A, by=df.C, foo="bar")
    def test_grouped_hist_legacy(self):
        from matplotlib.patches import Rectangle

        df = DataFrame(randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        df['D'] = ['X'] * 500

        axes = plotting.grouped_hist(df.A, by=df.C)
        self._check_axes_shape(axes, axes_num=4, layout=(2, 2))

        tm.close()
        axes = df.hist(by=df.C)
        self._check_axes_shape(axes, axes_num=4, layout=(2, 2))

        tm.close()
        # group by a key with single value
        axes = df.hist(by='D', rot=30)
        self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
        self._check_ticks_props(axes, xrot=30)

        tm.close()
        # make sure kwargs to hist are handled
        xf, yf = 20, 18
        xrot, yrot = 30, 40
        axes = plotting.grouped_hist(df.A,
                                     by=df.C,
                                     normed=True,
                                     cumulative=True,
                                     bins=4,
                                     xlabelsize=xf,
                                     xrot=xrot,
                                     ylabelsize=yf,
                                     yrot=yrot)
        # height of last bin (index 5) must be 1.0
        for ax in axes.ravel():
            rects = [x for x in ax.get_children() if isinstance(x, Rectangle)]
            height = rects[-1].get_height()
            self.assertAlmostEqual(height, 1.0)
        self._check_ticks_props(axes,
                                xlabelsize=xf,
                                xrot=xrot,
                                ylabelsize=yf,
                                yrot=yrot)

        tm.close()
        axes = plotting.grouped_hist(df.A, by=df.C, log=True)
        # scale of y must be 'log'
        self._check_ax_scales(axes, yaxis='log')

        tm.close()
        # propagate attr exception from matplotlib.Axes.hist
        with tm.assertRaises(AttributeError):
            plotting.grouped_hist(df.A, by=df.C, foo='bar')

        with tm.assert_produces_warning(FutureWarning):
            df.hist(by='C', figsize='default')
    def test_grouped_hist_legacy(self):
        from matplotlib.patches import Rectangle

        df = DataFrame(randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        df['D'] = ['X'] * 500

        axes = plotting.grouped_hist(df.A, by=df.C)
        self._check_axes_shape(axes, axes_num=4, layout=(2, 2))

        tm.close()
        axes = df.hist(by=df.C)
        self._check_axes_shape(axes, axes_num=4, layout=(2, 2))

        tm.close()
        # group by a key with single value
        axes = df.hist(by='D', rot=30)
        self._check_axes_shape(axes, axes_num=1, layout=(1, 1))
        self._check_ticks_props(axes, xrot=30)

        tm.close()
        # make sure kwargs to hist are handled
        xf, yf = 20, 18
        xrot, yrot = 30, 40
        axes = plotting.grouped_hist(df.A, by=df.C, normed=True,
                                     cumulative=True, bins=4,
                                     xlabelsize=xf, xrot=xrot,
                                     ylabelsize=yf, yrot=yrot)
        # height of last bin (index 5) must be 1.0
        for ax in axes.ravel():
            rects = [x for x in ax.get_children() if isinstance(x, Rectangle)]
            height = rects[-1].get_height()
            self.assertAlmostEqual(height, 1.0)
        self._check_ticks_props(axes, xlabelsize=xf, xrot=xrot,
                                ylabelsize=yf, yrot=yrot)

        tm.close()
        axes = plotting.grouped_hist(df.A, by=df.C, log=True)
        # scale of y must be 'log'
        self._check_ax_scales(axes, yaxis='log')

        tm.close()
        # propagate attr exception from matplotlib.Axes.hist
        with tm.assertRaises(AttributeError):
            plotting.grouped_hist(df.A, by=df.C, foo='bar')

        with tm.assert_produces_warning(FutureWarning):
            df.hist(by='C', figsize='default')
    def test_grouped_hist(self):
        import matplotlib.pyplot as plt
        df = DataFrame(np.random.randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        axes = plotting.grouped_hist(df.A, by=df.C)
        self.assert_(len(axes.ravel()) == 4)

        plt.close('all')
        axes = df.hist(by=df.C)
        self.assert_(axes.ndim == 2)
        self.assert_(len(axes.ravel()) == 4)

        for ax in axes.ravel():
            self.assert_(len(ax.patches) > 0)
Beispiel #7
0
    def test_grouped_hist(self):
        import matplotlib.pyplot as plt
        df = DataFrame(np.random.randn(500, 2), columns=['A', 'B'])
        df['C'] = np.random.randint(0, 4, 500)
        axes = plotting.grouped_hist(df.A, by=df.C)
        self.assert_(len(axes.ravel()) == 4)

        plt.close('all')
        axes = df.hist(by=df.C)
        self.assert_(axes.ndim == 2)
        self.assert_(len(axes.ravel()) == 4)

        for ax in axes.ravel():
            self.assert_(len(ax.patches) > 0)
Beispiel #8
0
 def test_grouped_hist(self):
     df = DataFrame(np.random.randn(50, 2), columns=['A', 'B'])
     df['C'] = np.random.randint(0, 3, 50)
     axes = plotting.grouped_hist(df.A, by=df.C)
     self.assert_(len(axes.ravel()) == 4)
Beispiel #9
0
 def test_grouped_hist(self):
     df = DataFrame(np.random.randn(50, 2), columns=['A', 'B'])
     df['C'] = np.random.randint(0, 3, 50)
     axes = plotting.grouped_hist(df.A, by=df.C)
     self.assert_(len(axes.ravel()) == 4)