From 1f905e3ab787f8010e32bbef0d0a208d8b37f3c6 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 17 Jul 2023 11:04:23 +0100 Subject: [PATCH 01/17] version bump to 2.0.1 --- README.rst | 2 +- anesthetic/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 38cd72ae..df3d24bb 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.0.0 +:Version: 2.0.1 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index afced147..3f390799 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.0.0' +__version__ = '2.0.1' From 1f479b7aaef8708fba00ace9d5c2905b2005627c Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 17 Jul 2023 11:08:40 +0100 Subject: [PATCH 02/17] add test for `beta` kwarg in WeightedDataFrame method `neff` --- tests/test_weighted_pandas.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index aab44e11..493e90c0 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -379,14 +379,18 @@ def test_WeightedDataFrame_sample(frame): def test_WeightedDataFrame_neff(frame): - neff = frame.neff() - assert isinstance(neff, float) - assert neff < len(frame) - assert neff > len(frame) * np.exp(-0.25) - - neff = frame.neff(1) - assert isinstance(neff, int) - assert neff == len(frame.T) + N_eff = frame.neff() + assert isinstance(N_eff, float) + assert N_eff < len(frame) + assert N_eff > len(frame) * np.exp(-0.25) + + N_eff = frame.neff(1) + assert isinstance(N_eff, int) + assert N_eff == len(frame.T) + + # beta kwarg + for beta in [0.5, 1, 2, np.inf, '0.5', 'equal', 'entropy', 'kish']: + assert frame.neff(beta=beta) == neff(frame.get_weights(), beta=beta) def test_WeightedDataFrame_compress(frame): From a42b9811c9e1d4d628509aab39aea3cbdf20e41c Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 17 Jul 2023 11:40:16 +0100 Subject: [PATCH 03/17] fix missing `beta` kwarg in `WeightedDataFrame.neff` --- anesthetic/weighted_pandas.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anesthetic/weighted_pandas.py b/anesthetic/weighted_pandas.py index 6d4a55fe..614796b7 100644 --- a/anesthetic/weighted_pandas.py +++ b/anesthetic/weighted_pandas.py @@ -10,7 +10,7 @@ from pandas.util._exceptions import find_stack_level from pandas.util import hash_pandas_object from numpy.ma import masked_array -from anesthetic.utils import (compress_weights, neff as neff_, quantile, +from anesthetic.utils import (compress_weights, neff, quantile, temporary_seed, adjust_docstrings) from pandas.core.dtypes.missing import notna @@ -222,10 +222,10 @@ def reset_index(self, level=None, drop=False, inplace=False, else: return answer.__finalize__(self, "reset_index") - def neff(self, axis=0): + def neff(self, axis=0, beta=1): """Effective number of samples.""" if self.isweighted(axis): - return neff_(self.get_weights(axis)) + return neff(self.get_weights(axis), beta=beta) else: return self.shape[axis] From e38462eebf3b23e6bcaa56c4cf668c1015103786 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 17 Jul 2023 15:29:08 +0100 Subject: [PATCH 04/17] remove the ylabel from `plot_1d`, otherwise pandas adds in the label "Frequency" messing with our plotting grid --- anesthetic/samples.py | 1 + 1 file changed, 1 insertion(+) diff --git a/anesthetic/samples.py b/anesthetic/samples.py index 6c324812..bd07ec6d 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -247,6 +247,7 @@ def plot_1d(self, axes=None, *args, **kwargs): self[x].plot(ax=ax, xlabel=xlabel, *args, **kwargs) ax.set_xlabel(xlabel) + ax.set_ylabel("") else: ax.plot([], []) From f810b8396e9cb65892dcde72e6051b9186e038ed Mon Sep 17 00:00:00 2001 From: lukashergt Date: Thu, 20 Jul 2023 09:20:05 +0100 Subject: [PATCH 05/17] remove the 1d ylabel also from `plot_2d`, otherwise pandas again puts in a "Frequency" label messing with our plotting grid --- anesthetic/samples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anesthetic/samples.py b/anesthetic/samples.py index 34477b3e..e3ed7c41 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -390,7 +390,7 @@ def plot_2d(self, axes=None, *args, **kwargs): xlabel = self.get_label(x) ylabel = self.get_label(y) if x == y: - self[x].plot(ax=ax.twin, xlabel=xlabel, + self[x].plot(ax=ax.twin, xlabel=xlabel, ylabel="", *args, **lkwargs) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) From 4418cd06083d655cc4de3f9206606586520526b6 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Thu, 20 Jul 2023 09:37:12 +0100 Subject: [PATCH 06/17] add `kind=fastkde` shortcut to `plot_2d` --- anesthetic/samples.py | 1 + 1 file changed, 1 insertion(+) diff --git a/anesthetic/samples.py b/anesthetic/samples.py index e3ed7c41..38d1abab 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -414,6 +414,7 @@ def plot_2d(self, axes=None, *args, **kwargs): 'kde': {'diagonal': 'kde_1d', 'lower': 'kde_2d'}, 'kde_1d': {'diagonal': 'kde_1d'}, 'kde_2d': {'lower': 'kde_2d'}, + 'fastkde': {'diagonal': 'fastkde_1d', 'lower': 'fastkde_2d'}, 'hist': {'diagonal': 'hist_1d', 'lower': 'hist_2d'}, 'hist_1d': {'diagonal': 'hist_1d'}, 'hist_2d': {'lower': 'hist_2d'}, From 0085b4c48e4f8cc92260685799f43f7f0412f461 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Thu, 20 Jul 2023 09:39:13 +0100 Subject: [PATCH 07/17] add test that checks that the 1d ylabels are indeed empty --- tests/test_samples.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_samples.py b/tests/test_samples.py index b4563fb9..c02e71c6 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -1380,6 +1380,23 @@ def test_samples_plot_labels(): assert samples.get_label(col) == ax.get_xlabel() +@pytest.mark.parametrize('kind', ['kde', 'hist', 'fastkde'] + if 'fastkde' in sys.modules else + ['kde', 'hist']) +def test_samples_empty_1d_ylabels(kind): + samples = read_chains('./tests/example_data/pc') + columns = ['x0', 'x1', 'x2', 'x3', 'x4'] + + axes = samples.plot_1d(columns, kind=kind+'_1d') + for col in columns: + assert axes[col].get_ylabel() == '' + + axes = samples.plot_2d(columns, kind=kind) + for col in columns: + assert axes[col][col].get_ylabel() == samples.get_labels_map()[col] + assert axes[col][col].twin.get_ylabel() == '' + + def test_constructors(): samples = read_chains('./tests/example_data/pc') From ffca27323bcf9e3fc0bd72d14a901fba39686390 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Thu, 20 Jul 2023 09:50:23 +0100 Subject: [PATCH 08/17] add `fig.align_labels()` to 2d plots, which aligns labels independent of the potentially different length of the tick labels (significantly improving appearance in my opinion) --- anesthetic/plot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/anesthetic/plot.py b/anesthetic/plot.py index eb5f6b47..b65b9494 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -697,6 +697,7 @@ def make_2d_axes(params, labels=None, lower=True, diagonal=True, upper=True, ticks=ticks, gridspec_kw=gridspec_kw, subplot_spec=subplot_spec) + fig.align_labels() return fig, axes From 9925b0708ce49413ed84d59bb27a0c6d4c3b3767 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 12:26:24 +0100 Subject: [PATCH 09/17] Neater way to correct for Frequency --- anesthetic/plotting/_matplotlib/hist.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index 2e51ee25..eceafe53 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -132,6 +132,7 @@ def _plot( return fastkde_plot_1d(ax, y, *args, **kwds) + class Hist1dPlot(HistPlot): # noqa: disable=D101 @property @@ -165,6 +166,13 @@ def _plot( cls._update_stacker(ax, stacking_id, n) return patches + def _post_plot_logic(self, ax, data) -> None: + if self.orientation == "horizontal": + ax.set_ylabel(self.ylabel) + else: + ax.set_xlabel(self.xlabel) + + class Kde2dPlot(_WeightedMPLPlot, _PlanePlot2d): # noqa: disable=D101 From f83e13290dc0c2fffed5f27c681ba2b34e4af641 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 12:28:05 +0100 Subject: [PATCH 10/17] Removed blank lines --- anesthetic/plotting/_matplotlib/hist.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index eceafe53..71196db6 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -132,7 +132,6 @@ def _plot( return fastkde_plot_1d(ax, y, *args, **kwds) - class Hist1dPlot(HistPlot): # noqa: disable=D101 @property @@ -173,7 +172,6 @@ def _post_plot_logic(self, ax, data) -> None: ax.set_xlabel(self.xlabel) - class Kde2dPlot(_WeightedMPLPlot, _PlanePlot2d): # noqa: disable=D101 @property From b02eb548c5b7829a856f6c6dd3a646d1783d9b2e Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 12:38:56 +0100 Subject: [PATCH 11/17] Added a test to check for frequency --- tests/test_samples.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_samples.py b/tests/test_samples.py index c02e71c6..9a3a2f96 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -1710,3 +1710,23 @@ def test_groupby_plots(): gb_colors = [p.get_facecolor() for p in gb_ax.patches] assert_allclose(mcmc_colors, gb_colors) plt.close('all') + + +def test_hist_1d_no_Frequency(): + np.random.seed(42) + pc = read_chains("./tests/example_data/pc") + axes = pc.plot_2d(['x0', 'x1', 'x2'], kind={'diagonal': 'hist_1d'}) + for i in range(len(axes)): + assert axes.iloc[i, i].twin.get_ylabel() != 'Frequency' + + axes = pc.plot_1d(['x0', 'x1', 'x2'], kind='hist_1d') + for ax in axes: + assert ax.get_ylabel() != 'Frequency' + + fig, ax = plt.subplots() + ax = pc['x0'].plot(kind='hist_1d', ax=ax) + assert ax.get_ylabel() != 'Frequency' + + fig, ax = plt.subplots() + ax = pc.x0.plot.hist_1d(ax=ax) + assert ax.get_ylabel() != 'Frequency' From 8cad72b5bb2f0db7e2a7900c275ee8f8a0e2407e Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 12:44:08 +0100 Subject: [PATCH 12/17] Removed previous fix --- anesthetic/samples.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/anesthetic/samples.py b/anesthetic/samples.py index 38d1abab..c454f682 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -247,7 +247,6 @@ def plot_1d(self, axes=None, *args, **kwargs): self[x].plot(ax=ax, xlabel=xlabel, *args, **kwargs) ax.set_xlabel(xlabel) - ax.set_ylabel("") else: ax.plot([], []) @@ -390,7 +389,7 @@ def plot_2d(self, axes=None, *args, **kwargs): xlabel = self.get_label(x) ylabel = self.get_label(y) if x == y: - self[x].plot(ax=ax.twin, xlabel=xlabel, ylabel="", + self[x].plot(ax=ax.twin, xlabel=xlabel, *args, **lkwargs) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) From 4c5d32b5c4c46bedbe0385bd6379e624bf805aa0 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 13:39:51 +0100 Subject: [PATCH 13/17] Fix for ranges --- anesthetic/plotting/_matplotlib/hist.py | 27 ++++++++++++++++++------- tests/test_samples.py | 10 ++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index 71196db6..097f42cf 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -19,7 +19,9 @@ kde_plot_1d, fastkde_plot_1d, hist_plot_1d, + quantile_plot_interval, ) +from anesthetic.utils import quantile class HistPlot(_WeightedMPLPlot, _HistPlot): @@ -51,7 +53,10 @@ def _get_colors(self, num_colors=None, color_kwds='color'): return super()._get_colors(num_colors, color_kwds) def _post_plot_logic(self, ax, data): - super()._post_plot_logic(ax, data) + if self.orientation == "horizontal": + ax.set_ylabel(self.ylabel) + else: + ax.set_xlabel(self.xlabel) ax.set_yticks([]) ax.set_ylim(bottom=0) ax.set_xlim(self.bins[0], self.bins[-1]) @@ -138,6 +143,20 @@ class Hist1dPlot(HistPlot): def _kind(self) -> Literal["hist_1d"]: return "hist_1d" + def _calculate_bins(self, data): + if range not in self.kwds: + q = self.kwds.get('q', 5) + q = quantile_plot_interval(q=q) + weights = self.kwds.get("weights", None) + xmin = quantile(data, q[0], weights) + xmax = quantile(data, q[-1], weights) + self.kwds["range"] = (xmin, xmax) + result = super()._calculate_bins(data) + self.kwds.pop("range") + else: + result = super()._calculate_bins(data) + return result + @classmethod def _plot( cls, @@ -165,12 +184,6 @@ def _plot( cls._update_stacker(ax, stacking_id, n) return patches - def _post_plot_logic(self, ax, data) -> None: - if self.orientation == "horizontal": - ax.set_ylabel(self.ylabel) - else: - ax.set_xlabel(self.xlabel) - class Kde2dPlot(_WeightedMPLPlot, _PlanePlot2d): # noqa: disable=D101 diff --git a/tests/test_samples.py b/tests/test_samples.py index 9a3a2f96..8e8633df 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -996,12 +996,12 @@ def test_hist_range_1d(): ns = read_chains('./tests/example_data/pc') ax = ns.plot_1d('x0', kind='hist_1d') x1, x2 = ax['x0'].get_xlim() - assert x1 > -1 - assert x2 < +1 - ax = ns.plot_1d('x0', kind='hist_1d', bins=np.linspace(-1, 1, 11)) + assert x1 > -0.5 + assert x2 < 0.5 + ax = ns.plot_1d('x0', kind='hist_1d', bins=np.linspace(-2, 2, 100)) x1, x2 = ax['x0'].get_xlim() - assert x1 <= -1 - assert x2 >= +1 + assert x1 <= -2 + assert x2 >= +2 def test_contour_plot_2d_nan(): From 28fc103db31ba201db377f428516e6d5803e20f3 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 14:43:45 +0100 Subject: [PATCH 14/17] Added tests to explictly check axes are adjusting correctly --- anesthetic/plot.py | 3 +- anesthetic/plotting/_matplotlib/hist.py | 1 - tests/test_samples.py | 74 ++++++++++++++++++++----- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/anesthetic/plot.py b/anesthetic/plot.py index b65b9494..d25a7e2e 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -1284,7 +1284,8 @@ def hist_plot_2d(ax, data_x, data_y, *args, **kwargs): pdf[pdf < cmin] = np.ma.masked if cmax is not None: pdf[pdf > cmax] = np.ma.masked - image = ax.pcolormesh(x, y, pdf.T, cmap=cmap, vmin=vmin, + snap = kwargs.pop('snap', True) + image = ax.pcolormesh(x, y, pdf.T, cmap=cmap, vmin=vmin, snap=snap, *args, **kwargs) ax.add_patch(plt.Rectangle((0, 0), 0, 0, fc=cmap(0.999), ec=cmap(0.32), diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index 097f42cf..b488a2e9 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -59,7 +59,6 @@ def _post_plot_logic(self, ax, data): ax.set_xlabel(self.xlabel) ax.set_yticks([]) ax.set_ylim(bottom=0) - ax.set_xlim(self.bins[0], self.bins[-1]) class KdePlot(HistPlot, _KdePlot): diff --git a/tests/test_samples.py b/tests/test_samples.py index 8e8633df..880bf6bf 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -990,20 +990,6 @@ def test_live_points(): assert not live_points.isweighted() -def test_hist_range_1d(): - """Test to provide a solution to #89""" - np.random.seed(3) - ns = read_chains('./tests/example_data/pc') - ax = ns.plot_1d('x0', kind='hist_1d') - x1, x2 = ax['x0'].get_xlim() - assert x1 > -0.5 - assert x2 < 0.5 - ax = ns.plot_1d('x0', kind='hist_1d', bins=np.linspace(-2, 2, 100)) - x1, x2 = ax['x0'].get_xlim() - assert x1 <= -2 - assert x2 >= +2 - - def test_contour_plot_2d_nan(): """Contour plots with nans arising from issue #96""" np.random.seed(3) @@ -1730,3 +1716,63 @@ def test_hist_1d_no_Frequency(): fig, ax = plt.subplots() ax = pc.x0.plot.hist_1d(ax=ax) assert ax.get_ylabel() != 'Frequency' + + +@pytest.mark.parametrize('kind', ['kde', 'hist']) +def test_axes_limits_1d(kind): + np.random.seed(42) + pc = read_chains("./tests/example_data/pc") + + axes = pc.plot_1d('x0', kind=f'{kind}_1d') + xmin, xmax = axes['x0'].get_xlim() + assert -0.9 < xmin < 0 + assert 0 < xmax < 0.9 + + pc.x0 += 3 + pc.plot_1d(axes, kind=f'{kind}_1d') + xmin, xmax = axes['x0'].get_xlim() + assert -0.9 < xmin < 0 + assert 3 < xmax < 3.9 + + pc.x0 -= 6 + pc.plot_1d(axes, kind=f'{kind}_1d') + xmin, xmax = axes['x0'].get_xlim() + assert -3.9 < xmin < -3 + assert 3 < xmax < 3.9 + + +@pytest.mark.parametrize('kind, kwargs', + [('kde', {}), + ('hist', {'levels': [0.95, 0.68]}), + ]) +def test_axes_limits_2d(kind, kwargs): + np.random.seed(42) + pc = read_chains("./tests/example_data/pc") + + axes = pc.plot_2d(['x0', 'x1'], kind=f'{kind}_2d', **kwargs) + xmin, xmax = axes['x0']['x1'].get_xlim() + ymin, ymax = axes['x0']['x1'].get_ylim() + assert -0.9 < xmin < 0 + assert 0 < xmax < 0.9 + assert -0.9 < ymin < 0 + assert 0 < ymax < 0.9 + + pc.x0 += 3 + pc.x1 -= 3 + pc.plot_2d(axes, kind=f'{kind}_2d', **kwargs) + xmin, xmax = axes['x0']['x1'].get_xlim() + ymin, ymax = axes['x0']['x1'].get_ylim() + assert -0.9 < xmin < 0 + assert 3 < xmax < 3.9 + assert -3.9 < ymin < -3 + assert 0 < ymax < 0.9 + + pc.x0 -= 6 + pc.x1 += 6 + pc.plot_2d(axes, kind=f'{kind}_2d', **kwargs) + xmin, xmax = axes['x0']['x1'].get_xlim() + ymin, ymax = axes['x0']['x1'].get_ylim() + assert -3.9 < xmin < -3 + assert 3 < xmax < 3.9 + assert -3.9 < ymin < -3 + assert 3 < ymax < 3.9 From 5267daaba1592bd2b998c49f9722b28ade8bd684 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 18:29:54 +0100 Subject: [PATCH 15/17] no support for horizontal --- anesthetic/plotting/_matplotlib/hist.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index b488a2e9..39333dbf 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -53,10 +53,7 @@ def _get_colors(self, num_colors=None, color_kwds='color'): return super()._get_colors(num_colors, color_kwds) def _post_plot_logic(self, ax, data): - if self.orientation == "horizontal": - ax.set_ylabel(self.ylabel) - else: - ax.set_xlabel(self.xlabel) + ax.set_xlabel(self.xlabel) ax.set_yticks([]) ax.set_ylim(bottom=0) From 50601e4169a2c5280b943cbd7e30a03bb43e9250 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Mon, 24 Jul 2023 23:21:38 +0100 Subject: [PATCH 16/17] Corrected ranges --- anesthetic/plot.py | 5 +++-- anesthetic/plotting/_matplotlib/hist.py | 2 +- tests/test_samples.py | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/anesthetic/plot.py b/anesthetic/plot.py index d25a7e2e..0a831196 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -965,17 +965,18 @@ def hist_plot_1d(ax, data, *args, **kwargs): q = quantile_plot_interval(q=q) xmin = quantile(data, q[0], weights) xmax = quantile(data, q[-1], weights) + range = kwargs.pop('range', (xmin, xmax)) if type(bins) == str and bins in ['knuth', 'freedman', 'blocks']: try: h, edges, bars = hist(data, ax=ax, bins=bins, - range=(xmin, xmax), histtype=histtype, + range=range, histtype=histtype, color=color, *args, **kwargs) except NameError: raise ImportError("You need to install astropy to use astropyhist") else: h, edges, bars = ax.hist(data, weights=weights, bins=bins, - range=(xmin, xmax), histtype=histtype, + range=range, histtype=histtype, color=color, *args, **kwargs) if histtype == 'bar' and not density: diff --git a/anesthetic/plotting/_matplotlib/hist.py b/anesthetic/plotting/_matplotlib/hist.py index 39333dbf..68c6b42c 100644 --- a/anesthetic/plotting/_matplotlib/hist.py +++ b/anesthetic/plotting/_matplotlib/hist.py @@ -140,7 +140,7 @@ def _kind(self) -> Literal["hist_1d"]: return "hist_1d" def _calculate_bins(self, data): - if range not in self.kwds: + if "range" not in self.kwds: q = self.kwds.get('q', 5) q = quantile_plot_interval(q=q) weights = self.kwds.get("weights", None) diff --git a/tests/test_samples.py b/tests/test_samples.py index 880bf6bf..329a0a81 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -1277,6 +1277,10 @@ def test_samples_dot_plot(): axes = samples.x2.plot.hist_1d(ax=ax) assert len(axes.containers) == 1 + fig, ax = plt.subplots() + axes = samples.x2.plot.hist_1d(ax=ax, range=[0, 0.2]) + assert axes.get_xlim()[1] < 0.3 + axes = samples.drop_labels().plot.kde_2d('x0', 'x1') assert len(axes.collections) == 5 assert axes.get_xlabel() == 'x0' From b3dfee753865a54ade01df9fe392ca8271f35c49 Mon Sep 17 00:00:00 2001 From: Will Handley Date: Wed, 26 Jul 2023 18:53:27 +0100 Subject: [PATCH 17/17] Bumped version --- README.rst | 2 +- anesthetic/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 27ee7e4a..a8fba59d 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.1.1 +:Version: 2.1.2 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 55fa725b..f8115612 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.1.1' +__version__ = '2.1.2'