Python matplotlib.cbook.boxplot_stats() Examples

The following are 30 code examples of matplotlib.cbook.boxplot_stats(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.cbook , or try the search function .
Example #1
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_results_bootstrapped(self):
        results = cbook.boxplot_stats(self.data, bootstrap=10000)
        res = results[0]
        for key in list(self.known_bootstrapped_ci.keys()):
            assert_approx_equal(
                res[key],
                self.known_bootstrapped_ci[key]
            ) 
Example #2
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_boxplot_stats_autorange_false(self):
        x = np.zeros(shape=140)
        x = np.hstack([-25, x, 25])
        bstats_false = cbook.boxplot_stats(x, autorange=False)
        bstats_true = cbook.boxplot_stats(x, autorange=True)

        assert bstats_false[0]['whislo'] == 0
        assert bstats_false[0]['whishi'] == 0
        assert_array_almost_equal(bstats_false[0]['fliers'], [-25, 25])

        assert bstats_true[0]['whislo'] == -25
        assert bstats_true[0]['whishi'] == 25
        assert_array_almost_equal(bstats_true[0]['fliers'], []) 
Example #3
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_bad_dims(self):
        data = np.random.normal(size=(34, 34, 34))
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(data) 
Example #4
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_label_error(self):
        labels = [1, 2]
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(self.data, labels=labels) 
Example #5
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_results_whiskers_percentiles(self):
        results = cbook.boxplot_stats(self.data, whis=[5, 95])
        res = results[0]
        for key, value in self.known_res_percentiles.items():
            assert_array_almost_equal(res[key], value) 
Example #6
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_results_whiskers_range(self):
        results = cbook.boxplot_stats(self.data, whis='range')
        res = results[0]
        for key, value in self.known_res_range.items():
            assert_array_almost_equal(res[key], value) 
Example #7
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_results_whiskers_float(self):
        results = cbook.boxplot_stats(self.data, whis=3)
        res = results[0]
        for key, value in self.known_whis3_res.items():
            assert_array_almost_equal(res[key], value) 
Example #8
Source File: test_cbook.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_results_bootstrapped(self):
        results = cbook.boxplot_stats(self.data, bootstrap=10000)
        res = results[0]
        for key, value in self.known_bootstrapped_ci.items():
            assert_approx_equal(res[key], value) 
Example #9
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_boxplot_stats_autorange_false(self):
        x = np.zeros(shape=140)
        x = np.hstack([-25, x, 25])
        bstats_false = cbook.boxplot_stats(x, autorange=False)
        bstats_true = cbook.boxplot_stats(x, autorange=True)

        assert bstats_false[0]['whislo'] == 0
        assert bstats_false[0]['whishi'] == 0
        assert_array_almost_equal(bstats_false[0]['fliers'], [-25, 25])

        assert bstats_true[0]['whislo'] == -25
        assert bstats_true[0]['whishi'] == 25
        assert_array_almost_equal(bstats_true[0]['fliers'], []) 
Example #10
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_bad_dims(self):
        data = np.random.normal(size=(34, 34, 34))
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(data) 
Example #11
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_label_error(self):
        labels = [1, 2]
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(self.data, labels=labels) 
Example #12
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_results_whiskers_percentiles(self):
        results = cbook.boxplot_stats(self.data, whis=[5, 95])
        res = results[0]
        for key, value in self.known_res_percentiles.items():
            assert_array_almost_equal(res[key], value) 
Example #13
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_results_whiskers_range(self):
        results = cbook.boxplot_stats(self.data, whis='range')
        res = results[0]
        for key, value in self.known_res_range.items():
            assert_array_almost_equal(res[key], value) 
Example #14
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_results_whiskers_float(self):
        results = cbook.boxplot_stats(self.data, whis=3)
        res = results[0]
        for key, value in self.known_whis3_res.items():
            assert_array_almost_equal(res[key], value) 
Example #15
Source File: test_cbook.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_results_bootstrapped(self):
        results = cbook.boxplot_stats(self.data, bootstrap=10000)
        res = results[0]
        for key, value in self.known_bootstrapped_ci.items():
            assert_approx_equal(res[key], value) 
Example #16
Source File: stat_boxplot.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def compute_group(cls, data, scales, **params):
        labels = ['x', 'y']
        X = np.array(data[labels])
        res = boxplot_stats(X, whis=params['coef'], labels=labels)[1]
        try:
            n = data['weight'].sum()
        except KeyError:
            n = len(data['y'])

        if len(np.unique(data['x'])) > 1:
            width = np.ptp(data['x']) * 0.9
        else:
            width = params['width']

        if pdtypes.is_categorical(data['x']):
            x = data['x'].iloc[0]
        else:
            x = np.mean([data['x'].min(), data['x'].max()])

        d = {'ymin': res['whislo'],
             'lower': res['q1'],
             'middle': [res['med']],
             'upper': res['q3'],
             'ymax': res['whishi'],
             'outliers': [res['fliers']],
             'notchupper': res['med']+1.58*res['iqr']/np.sqrt(n),
             'notchlower': res['med']-1.58*res['iqr']/np.sqrt(n),
             'x': x,
             'width': width,
             'relvarwidth': np.sqrt(n)}
        return pd.DataFrame(d) 
Example #17
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_boxplot_stats_autorange_false(self):
        x = np.zeros(shape=140)
        x = np.hstack([-25, x, 25])
        bstats_false = cbook.boxplot_stats(x, autorange=False)
        bstats_true = cbook.boxplot_stats(x, autorange=True)

        assert bstats_false[0]['whislo'] == 0
        assert bstats_false[0]['whishi'] == 0
        assert_array_almost_equal(bstats_false[0]['fliers'], [-25, 25])

        assert bstats_true[0]['whislo'] == -25
        assert bstats_true[0]['whishi'] == 25
        assert_array_almost_equal(bstats_true[0]['fliers'], []) 
Example #18
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_bad_dims(self):
        data = np.random.normal(size=(34, 34, 34))
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(data) 
Example #19
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_label_error(self):
        labels = [1, 2]
        with pytest.raises(ValueError):
            results = cbook.boxplot_stats(self.data, labels=labels) 
Example #20
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_results_whiskers_percentiles(self):
        results = cbook.boxplot_stats(self.data, whis=[5, 95])
        res = results[0]
        for key, value in self.known_res_percentiles.items():
            assert_array_almost_equal(res[key], value) 
Example #21
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_results_whiskers_range(self):
        results = cbook.boxplot_stats(self.data, whis='range')
        res = results[0]
        for key, value in self.known_res_range.items():
            assert_array_almost_equal(res[key], value) 
Example #22
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_results_whiskers_float(self):
        results = cbook.boxplot_stats(self.data, whis=3)
        res = results[0]
        for key, value in self.known_whis3_res.items():
            assert_array_almost_equal(res[key], value) 
Example #23
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_results_bootstrapped(self):
        results = cbook.boxplot_stats(self.data, bootstrap=10000)
        res = results[0]
        for key, value in self.known_bootstrapped_ci.items():
            assert_approx_equal(res[key], value) 
Example #24
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_results_whiskers_float(self):
        results = cbook.boxplot_stats(self.data, whis=3)
        res = results[0]
        for key in list(self.known_whis3_res.keys()):
            if key != 'fliers':
                assert_statement = assert_approx_equal
            else:
                assert_statement = assert_array_almost_equal

            assert_statement(
                res[key],
                self.known_whis3_res[key]
            ) 
Example #25
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_results_whiskers_range(self):
        results = cbook.boxplot_stats(self.data, whis='range')
        res = results[0]
        for key in list(self.known_res_range.keys()):
            if key != 'fliers':
                assert_statement = assert_approx_equal
            else:
                assert_statement = assert_array_almost_equal

            assert_statement(
                res[key],
                self.known_res_range[key]
            ) 
Example #26
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_bad_dims(self):
        data = np.random.normal(size=(34, 34, 34))
        results = cbook.boxplot_stats(data) 
Example #27
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_label_error(self):
        labels = [1, 2]
        results = cbook.boxplot_stats(self.data, labels=labels) 
Example #28
Source File: test_cbook.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_results_whiskers_percentiles(self):
        results = cbook.boxplot_stats(self.data, whis=[5, 95])
        res = results[0]
        for key in list(self.known_res_percentiles.keys()):
            if key != 'fliers':
                assert_statement = assert_approx_equal
            else:
                assert_statement = assert_array_almost_equal

            assert_statement(
                res[key],
                self.known_res_percentiles[key]
            ) 
Example #29
Source File: test_cbook.py    From neural-network-animation with MIT License 4 votes vote down vote up
def setup(self):
        np.random.seed(937)
        self.nrows = 37
        self.ncols = 4
        self.data = np.random.lognormal(size=(self.nrows, self.ncols),
                                        mean=1.5, sigma=1.75)
        self.known_keys = sorted([
            'mean', 'med', 'q1', 'q3', 'iqr',
            'cilo', 'cihi', 'whislo', 'whishi',
            'fliers', 'label'
        ])
        self.std_results = cbook.boxplot_stats(self.data)

        self.known_nonbootstrapped_res = {
            'cihi': 6.8161283264444847,
            'cilo': -0.1489815330368689,
            'iqr': 13.492709959447094,
            'mean': 13.00447442387868,
            'med': 3.3335733967038079,
            'fliers': np.array([
                92.55467075,  87.03819018,  42.23204914,  39.29390996
            ]),
            'q1': 1.3597529879465153,
            'q3': 14.85246294739361,
            'whishi': 27.899688243699629,
            'whislo': 0.042143774965502923
        }

        self.known_bootstrapped_ci = {
            'cihi': 8.939577523357828,
            'cilo': 1.8692703958676578,
        }

        self.known_whis3_res = {
            'whishi': 42.232049135969874,
            'whislo': 0.042143774965502923,
            'fliers': np.array([92.55467075, 87.03819018]),
        }

        self.known_res_percentiles = {
            'whislo':   0.1933685896907924,
            'whishi':  42.232049135969874
        }

        self.known_res_range = {
            'whislo': 0.042143774965502923,
            'whishi': 92.554670752188699

        } 
Example #30
Source File: test_cbook.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def setup(self):
        np.random.seed(937)
        self.nrows = 37
        self.ncols = 4
        self.data = np.random.lognormal(size=(self.nrows, self.ncols),
                                        mean=1.5, sigma=1.75)
        self.known_keys = sorted([
            'mean', 'med', 'q1', 'q3', 'iqr',
            'cilo', 'cihi', 'whislo', 'whishi',
            'fliers', 'label'
        ])
        self.std_results = cbook.boxplot_stats(self.data)

        self.known_nonbootstrapped_res = {
            'cihi': 6.8161283264444847,
            'cilo': -0.1489815330368689,
            'iqr': 13.492709959447094,
            'mean': 13.00447442387868,
            'med': 3.3335733967038079,
            'fliers': np.array([
                92.55467075,  87.03819018,  42.23204914,  39.29390996
            ]),
            'q1': 1.3597529879465153,
            'q3': 14.85246294739361,
            'whishi': 27.899688243699629,
            'whislo': 0.042143774965502923
        }

        self.known_bootstrapped_ci = {
            'cihi': 8.939577523357828,
            'cilo': 1.8692703958676578,
        }

        self.known_whis3_res = {
            'whishi': 42.232049135969874,
            'whislo': 0.042143774965502923,
            'fliers': np.array([92.55467075, 87.03819018]),
        }

        self.known_res_percentiles = {
            'whislo':   0.1933685896907924,
            'whishi':  42.232049135969874
        }

        self.known_res_range = {
            'whislo': 0.042143774965502923,
            'whishi': 92.554670752188699

        }