Ejemplo n.º 1
0
 def test_grouped_hist_legacy2(self):
     n = 10
     weight = Series(np.random.normal(166, 20, size=n))
     height = Series(np.random.normal(60, 10, size=n))
     with tm.RNGContext(42):
         gender_int = np.random.choice([0, 1], size=n)
     df_int = DataFrame({
         'height': height,
         'weight': weight,
         'gender': gender_int
     })
     gb = df_int.groupby('gender')
     axes = gb.hist()
     self.assertEqual(len(axes), 2)
     self.assertEqual(len(self.plt.get_fignums()), 2)
     tm.close()
    def setup_method(self, method):

        import matplotlib as mpl
        mpl.rcdefaults()

        self.mpl_le_1_2_1 = plotting._compat._mpl_le_1_2_1()
        self.mpl_ge_1_3_1 = plotting._compat._mpl_ge_1_3_1()
        self.mpl_ge_1_4_0 = plotting._compat._mpl_ge_1_4_0()
        self.mpl_ge_1_5_0 = plotting._compat._mpl_ge_1_5_0()
        self.mpl_ge_2_0_0 = plotting._compat._mpl_ge_2_0_0()
        self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1()
        self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0()

        if self.mpl_ge_1_4_0:
            self.bp_n_objects = 7
        else:
            self.bp_n_objects = 8
        if self.mpl_ge_1_5_0:
            # 1.5 added PolyCollections to legend handler
            # so we have twice as many items.
            self.polycollection_factor = 2
        else:
            self.polycollection_factor = 1

        if self.mpl_ge_2_0_0:
            self.default_figsize = (6.4, 4.8)
        else:
            self.default_figsize = (8.0, 6.0)
        self.default_tick_position = 'left' if self.mpl_ge_2_0_0 else 'default'

        n = 100
        with tm.RNGContext(42):
            gender = np.random.choice(['Male', 'Female'], size=n)
            classroom = np.random.choice(['A', 'B', 'C'], size=n)

            self.hist_df = DataFrame({'gender': gender,
                                      'classroom': classroom,
                                      'height': random.normal(66, 4, size=n),
                                      'weight': random.normal(161, 32, size=n),
                                      'category': random.randint(4, size=n)})

        self.tdf = tm.makeTimeDataFrame()
        self.hexbin_df = DataFrame({"A": np.random.uniform(size=20),
                                    "B": np.random.uniform(size=20),
                                    "C": np.arange(20) + np.random.uniform(
                                        size=20)})
Ejemplo n.º 3
0
    def test_scatter_matrix_axis(self):
        tm._skip_if_no_scipy()
        scatter_matrix = plotting.scatter_matrix

        with tm.RNGContext(42):
            df = DataFrame(randn(100, 3))

        # we are plotting multiples on a sub-plot
        with tm.assert_produces_warning(UserWarning):
            axes = _check_plot_works(scatter_matrix,
                                     filterwarnings='always',
                                     frame=df,
                                     range_padding=.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()

        # GH 5662
        if self.mpl_ge_2_0_0:
            expected = ['-2', '0', '2']
        else:
            expected = ['-2', '-1', '0', '1', '2']
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes,
                                xlabelsize=8,
                                xrot=90,
                                ylabelsize=8,
                                yrot=0)

        df[0] = ((df[0] - 2) / 3)

        # we are plotting multiples on a sub-plot
        with tm.assert_produces_warning(UserWarning):
            axes = _check_plot_works(scatter_matrix,
                                     filterwarnings='always',
                                     frame=df,
                                     range_padding=.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
        if self.mpl_ge_2_0_0:
            expected = ['-1.0', '-0.5', '0.0']
        else:
            expected = ['-1.2', '-1.0', '-0.8', '-0.6', '-0.4', '-0.2', '0.0']
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes,
                                xlabelsize=8,
                                xrot=90,
                                ylabelsize=8,
                                yrot=0)
Ejemplo n.º 4
0
    def test_grouped_plot_fignums(self):
        n = 10
        weight = Series(np.random.normal(166, 20, size=n))
        height = Series(np.random.normal(60, 10, size=n))
        with tm.RNGContext(42):
            gender = np.random.choice(['male', 'female'], size=n)
        df = DataFrame({'height': height, 'weight': weight, 'gender': gender})
        gb = df.groupby('gender')

        res = gb.plot()
        self.assertEqual(len(self.plt.get_fignums()), 2)
        self.assertEqual(len(res), 2)
        tm.close()

        res = gb.boxplot(return_type='axes')
        self.assertEqual(len(self.plt.get_fignums()), 1)
        self.assertEqual(len(res), 2)
        tm.close()

        # now works with GH 5610 as gender is excluded
        res = df.groupby('gender').hist()
        tm.close()
Ejemplo n.º 5
0
    def setup_method(self, method):

        import matplotlib as mpl
        from pandas.plotting._matplotlib import compat

        mpl.rcdefaults()

        self.mpl_ge_2_2_3 = compat._mpl_ge_2_2_3()
        self.mpl_ge_3_0_0 = compat._mpl_ge_3_0_0()
        self.mpl_ge_3_1_0 = compat._mpl_ge_3_1_0()

        self.bp_n_objects = 7
        self.polycollection_factor = 2
        self.default_figsize = (6.4, 4.8)
        self.default_tick_position = "left"

        n = 100
        with tm.RNGContext(42):
            gender = np.random.choice(["Male", "Female"], size=n)
            classroom = np.random.choice(["A", "B", "C"], size=n)

            self.hist_df = DataFrame(
                {
                    "gender": gender,
                    "classroom": classroom,
                    "height": random.normal(66, 4, size=n),
                    "weight": random.normal(161, 32, size=n),
                    "category": random.randint(4, size=n),
                }
            )

        self.tdf = tm.makeTimeDataFrame()
        self.hexbin_df = DataFrame(
            {
                "A": np.random.uniform(size=20),
                "B": np.random.uniform(size=20),
                "C": np.arange(20) + np.random.uniform(size=20),
            }
        )
Ejemplo n.º 6
0
    def test_scatter_matrix_axis(self):
        scatter_matrix = plotting.scatter_matrix

        with tm.RNGContext(42):
            df = DataFrame(randn(100, 3))

        # we are plotting multiples on a sub-plot
        with tm.assert_produces_warning(UserWarning):
            axes = _check_plot_works(scatter_matrix,
                                     filterwarnings="always",
                                     frame=df,
                                     range_padding=0.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()

        # GH 5662
        expected = ["-2", "0", "2"]
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes,
                                xlabelsize=8,
                                xrot=90,
                                ylabelsize=8,
                                yrot=0)

        df[0] = (df[0] - 2) / 3

        # we are plotting multiples on a sub-plot
        with tm.assert_produces_warning(UserWarning):
            axes = _check_plot_works(scatter_matrix,
                                     filterwarnings="always",
                                     frame=df,
                                     range_padding=0.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
        expected = ["-1.0", "-0.5", "0.0"]
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes,
                                xlabelsize=8,
                                xrot=90,
                                ylabelsize=8,
                                yrot=0)
Ejemplo n.º 7
0
    def test_scatter_matrix_axis(self):
        tm._skip_if_no_scipy()
        scatter_matrix = plotting.scatter_matrix

        with tm.RNGContext(42):
            df = DataFrame(randn(100, 3))

        axes = _check_plot_works(scatter_matrix, filterwarnings='always', frame=df,
                                 range_padding=.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
        # GH 5662
        expected = ['-2', '-1', '0', '1', '2']
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)

        df[0] = ((df[0] - 2) / 3)
        axes = _check_plot_works(scatter_matrix, filterwarnings='always', frame=df,
                                 range_padding=.1)
        axes0_labels = axes[0][0].yaxis.get_majorticklabels()
        expected = ['-1.2', '-1.0', '-0.8', '-0.6', '-0.4', '-0.2', '0.0']
        self._check_text_labels(axes0_labels, expected)
        self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
Ejemplo n.º 8
0
    def test_grouped_plot_fignums(self):
        n = 10
        weight = Series(np.random.normal(166, 20, size=n))
        height = Series(np.random.normal(60, 10, size=n))
        with tm.RNGContext(42):
            gender = np.random.choice(["male", "female"], size=n)
        df = DataFrame({"height": height, "weight": weight, "gender": gender})
        gb = df.groupby("gender")

        res = gb.plot()
        assert len(self.plt.get_fignums()) == 2
        assert len(res) == 2
        tm.close()

        res = gb.boxplot(return_type="axes")
        assert len(self.plt.get_fignums()) == 1
        assert len(res) == 2
        tm.close()

        # now works with GH 5610 as gender is excluded
        res = df.groupby("gender").hist()
        tm.close()
Ejemplo n.º 9
0
    def setup_method(self, method):

        import matplotlib as mpl
        mpl.rcdefaults()

        self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1()
        self.mpl_ge_2_1_0 = plotting._compat._mpl_ge_2_1_0()
        self.mpl_ge_2_2_0 = plotting._compat._mpl_ge_2_2_0()
        self.mpl_ge_2_2_2 = plotting._compat._mpl_ge_2_2_2()
        self.mpl_ge_3_0_0 = plotting._compat._mpl_ge_3_0_0()

        self.bp_n_objects = 7
        self.polycollection_factor = 2
        self.default_figsize = (6.4, 4.8)
        self.default_tick_position = 'left'

        n = 100
        with tm.RNGContext(42):
            gender = np.random.choice(['Male', 'Female'], size=n)
            classroom = np.random.choice(['A', 'B', 'C'], size=n)

            self.hist_df = DataFrame({
                'gender': gender,
                'classroom': classroom,
                'height': random.normal(66, 4, size=n),
                'weight': random.normal(161, 32, size=n),
                'category': random.randint(4, size=n)
            })

        self.tdf = tm.makeTimeDataFrame()
        self.hexbin_df = DataFrame({
            "A":
            np.random.uniform(size=20),
            "B":
            np.random.uniform(size=20),
            "C":
            np.arange(20) + np.random.uniform(size=20)
        })