From 32769e891b2c39ddde03fa0f33036491fae37868 Mon Sep 17 00:00:00 2001 From: Lukas Hergt Date: Wed, 24 Apr 2024 11:03:03 -0700 Subject: [PATCH 1/5] Fix logscale limit updates (#383) * test that limits get accurately updated by successive plots with logscale axes, adjusting to new data limits, see issue #381 * fix typo from PR #324 * bump version to 2.8.10 * update logscale plot limits to datalimits at the end, making use of `ax.dataLim` --- README.rst | 2 +- anesthetic/_version.py | 2 +- anesthetic/plot.py | 4 ++++ anesthetic/samples.py | 2 +- tests/test_samples.py | 21 ++++++++++++++++----- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 84fcd8af..e8fd0bc6 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.8.9 +:Version: 2.8.10 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index bf560199..8728008c 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.9' +__version__ = '2.8.10' diff --git a/anesthetic/plot.py b/anesthetic/plot.py index 561fa2da..05bedacf 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -394,8 +394,12 @@ def _set_logticks(self): if ax is not None: if x in self._logx: ax.xaxis.set_major_locator(LogLocator(numticks=3)) + if x != y: + ax.set_xlim(ax.dataLim.intervalx) if y in self._logy: ax.yaxis.set_major_locator(LogLocator(numticks=3)) + if y != x: + ax.set_ylim(ax.dataLim.intervaly) @staticmethod def _set_labels(axes, labels, **kwargs): diff --git a/anesthetic/samples.py b/anesthetic/samples.py index 605d5fbe..d0dee2b1 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -356,7 +356,7 @@ def plot_2d(self, axes=None, *args, **kwargs): if np.isinf(self[x]).any(): warnings.warn(f"column {y} has inf values.") selfxy = self[[x, y]] - selfxy = self.replace([-np.inf, np.inf], np.nan) + selfxy = selfxy.replace([-np.inf, np.inf], np.nan) selfxy = selfxy.dropna(axis=0) selfxy.plot(x, y, ax=ax, xlabel=xlabel, logx=x in logx, logy=y in logy, diff --git a/tests/test_samples.py b/tests/test_samples.py index bea15c4f..7addabe8 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -526,13 +526,16 @@ def test_plot_logscale_2d(kind): def test_logscale_ticks(): np.random.seed(42) ndim = 5 - data = np.exp(10 * np.random.randn(200, ndim)) + data1 = np.exp(10 * np.random.randn(200, ndim)) + data2 = np.exp(10 * np.random.randn(200, ndim) - 50) params = [f'a{i}' for i in range(ndim)] fig, axes = make_2d_axes(params, logx=params, logy=params, upper=False) - samples = Samples(data, columns=params) - samples.plot_2d(axes) - for _, col in axes.iterrows(): - for _, ax in col.items(): + samples1 = Samples(data1, columns=params) + samples2 = Samples(data2, columns=params) + samples1.plot_2d(axes) + samples2.plot_2d(axes) + for y, col in axes.iterrows(): + for x, ax in col.items(): if ax is not None: xlims = ax.get_xlim() xticks = ax.get_xticks() @@ -540,6 +543,14 @@ def test_logscale_ticks(): ylims = ax.get_ylim() yticks = ax.get_yticks() assert np.sum((yticks > ylims[0]) & (yticks < ylims[1])) > 1 + if x == y: + data_min = ax.twin.dataLim.intervalx[0] + data_max = ax.twin.dataLim.intervalx[1] + assert xlims[0] == pytest.approx(data_min, rel=1e-14) + assert xlims[1] == pytest.approx(data_max, rel=1e-14) + else: + assert_array_equal(xlims, ax.dataLim.intervalx) + assert_array_equal(ylims, ax.dataLim.intervaly) @pytest.mark.parametrize('k', ['hist_1d', 'hist']) From bd402c45a5c2638ab70d60da9198bb7ed3189738 Mon Sep 17 00:00:00 2001 From: Lukas Hergt Date: Wed, 24 Apr 2024 13:26:01 -0700 Subject: [PATCH 2/5] Fix macOS CI (#385) * attempt at fixing macOS CI by brew installing hdf5 * update from `miniconda@v2` to `miniconda@v3` * bump version to 2.8.11 * try newer `tables` version, which was previously restricted to 3.8.0 in #379 * Revert "attempt at fixing macOS CI by brew installing hdf5" This reverts commit 968bdb34e53bb50f524ac561be285412496ec53f. * Reapply "attempt at fixing macOS CI by brew installing hdf5" This reverts commit 204014ab3c10264a32ce2dfa37d239730c8249c5. Seems like this is needed after all, otherwise macOS is struggling to find a local HDF5. --------- Co-authored-by: Will Handley --- .github/workflows/CI.yaml | 8 +++++++- README.rst | 2 +- anesthetic/_version.py | 2 +- pyproject.toml | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 01a690e1..a662ba6a 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -72,6 +72,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install hdf5 for macOS + if: ${{ matrix.os == 'macos-latest' }} + run: brew install hdf5 c-blosc - name: Install dependencies run: | @@ -107,9 +110,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v3 with: python-version: ${{ matrix.python-version }} + - name: Install hdf5 for macOS + if: ${{ matrix.os == 'macos-latest' }} + run: brew install hdf5 c-blosc - name: Install dependencies shell: bash -l {0} diff --git a/README.rst b/README.rst index e8fd0bc6..1c16e388 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.8.10 +:Version: 2.8.11 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 8728008c..9a2e0c8b 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.10' +__version__ = '2.8.11' diff --git a/pyproject.toml b/pyproject.toml index ff1d6db3..94caa394 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ astropy = ["astropy"] fastkde = ["fastkde"] getdist = ["getdist"] hdf5 = ["tables==3.8.0"] -all = ["h5py", "astropy", "fastkde", "getdist", "tables==3.8.0"] +all = ["h5py", "astropy", "fastkde", "getdist", "tables"] [project.scripts] anesthetic = "anesthetic.scripts:gui" From 8726a904dbdbe3663f93d7ce9fc841d742b5beca Mon Sep 17 00:00:00 2001 From: Will Handley Date: Wed, 24 Apr 2024 21:43:32 +0100 Subject: [PATCH 3/5] Fix to `color='C2'` plot_2d error post pandas 2 (#382) * Added failing test * bump version to 2.8.10 * Get color from self.color * Update README.rst * Update _version.py * Update README.rst * Update _version.py --------- Co-authored-by: Lukas Hergt --- README.rst | 2 +- anesthetic/_version.py | 2 +- anesthetic/plotting/_matplotlib/core.py | 2 ++ tests/test_samples.py | 32 ++++++++++++------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.rst b/README.rst index 1c16e388..53e3bbee 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.8.11 +:Version: 2.8.12 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 9a2e0c8b..2819820c 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.11' +__version__ = '2.8.12' diff --git a/anesthetic/plotting/_matplotlib/core.py b/anesthetic/plotting/_matplotlib/core.py index 8d5ca090..ce13b692 100644 --- a/anesthetic/plotting/_matplotlib/core.py +++ b/anesthetic/plotting/_matplotlib/core.py @@ -100,6 +100,8 @@ def _make_plot(self, fig): ax = self._get_ax(0) # another one of these hard-coded 0s kwds = self.kwds.copy() + if self.color is not None: + kwds["color"] = self.color label = pprint_thing(self.label) kwds["label"] = label diff --git a/tests/test_samples.py b/tests/test_samples.py index 7addabe8..f49aed3d 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -308,31 +308,29 @@ def test_plot_2d_colours(kind): kinds = {'diagonal': kind + '_1d', 'lower': kind + '_2d', 'upper': 'scatter_2d'} - gd.plot_2d(axes, kind=kinds, label="gd") - pc.plot_2d(axes, kind=kinds, label="pc") - mn.plot_2d(axes, kind=kinds, label="mn") - gd_colors = [] - pc_colors = [] - mn_colors = [] + gd.plot_2d(axes, kind=kinds, label="A") + pc.plot_2d(axes, kind=kinds, label="B") + mn.plot_2d(axes, kind=kinds, label="C") + gd.plot_2d(axes, kind=kinds, label="D", color='C7') + pc.plot_2d(axes, kind=kinds, label="E", color='C6') + mn.plot_2d(axes, kind=kinds, label="F", color='C5') + + from collections import defaultdict + d = defaultdict(set) + for y, rows in axes.iterrows(): for x, ax in rows.items(): handles, labels = ax.get_legend_handles_labels() for handle, label in zip(handles, labels): if isinstance(handle, Rectangle): - color = to_hex(handle.get_facecolor()) + color = handle.get_facecolor() else: color = handle.get_color() + color = to_hex(color) + d[label].add(color) - if label == 'gd': - gd_colors.append(color) - elif label == 'pc': - pc_colors.append(color) - elif label == 'mn': - mn_colors.append(color) - - assert len(set(gd_colors)) == 1 - assert len(set(mn_colors)) == 1 - assert len(set(pc_colors)) == 1 + for v in d.values(): + assert len(v) == 1 @pytest.mark.parametrize('kwargs', [dict(color='r', alpha=0.5, ls=':', lw=1), From 5b6b19919af009dc182d8d120c63a005a9549e0b Mon Sep 17 00:00:00 2001 From: Adam Ormondroyd <52655393+AdamOrmondroyd@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:00:54 +0100 Subject: [PATCH 4/5] allow matplotlib 3.9 (#387) * allow matplotlib 3.9 * bump version to 2.8.10 * Fix logscale limit updates (#383) * test that limits get accurately updated by successive plots with logscale axes, adjusting to new data limits, see issue #381 * fix typo from PR #324 * bump version to 2.8.10 * update logscale plot limits to datalimits at the end, making use of `ax.dataLim` * Fix macOS CI (#385) * attempt at fixing macOS CI by brew installing hdf5 * update from `miniconda@v2` to `miniconda@v3` * bump version to 2.8.11 * try newer `tables` version, which was previously restricted to 3.8.0 in #379 * Revert "attempt at fixing macOS CI by brew installing hdf5" This reverts commit 968bdb34e53bb50f524ac561be285412496ec53f. * Reapply "attempt at fixing macOS CI by brew installing hdf5" This reverts commit 204014ab3c10264a32ce2dfa37d239730c8249c5. Seems like this is needed after all, otherwise macOS is struggling to find a local HDF5. --------- Co-authored-by: Will Handley * Fix to `color='C2'` plot_2d error post pandas 2 (#382) * Added failing test * bump version to 2.8.10 * Get color from self.color * Update README.rst * Update _version.py * Update README.rst * Update _version.py --------- Co-authored-by: Lukas Hergt * bump version to 2.8.10 * bump version to 2.8.11 * bump version to 2.8.13 --------- Co-authored-by: Lukas Hergt Co-authored-by: Will Handley --- README.rst | 2 +- anesthetic/_version.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 53e3bbee..f6e4a3a2 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.8.12 +:Version: 2.8.13 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 2819820c..8651a139 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.12' +__version__ = '2.8.13' diff --git a/pyproject.toml b/pyproject.toml index 94caa394..8b6cd76c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "scipy", "numpy", "pandas~=2.2.0", - "matplotlib>=3.6.1,<3.9.0", + "matplotlib>=3.6.1,<3.10.0", ] classifiers = [ "Programming Language :: Python :: 3", From d367a4b8df0d3cd4da91204475726893a7aead47 Mon Sep 17 00:00:00 2001 From: Adam Ormondroyd <52655393+AdamOrmondroyd@users.noreply.github.com> Date: Wed, 3 Jul 2024 08:28:26 +0100 Subject: [PATCH 5/5] Restrict scipy and numpy versions (#390) * restrict scipy and numpy versions * bump version to 2.8.14 --- README.rst | 2 +- anesthetic/_version.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index f6e4a3a2..5e4e2096 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.8.13 +:Version: 2.8.14 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 8651a139..965b8c85 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.13' +__version__ = '2.8.14' diff --git a/pyproject.toml b/pyproject.toml index 8b6cd76c..61a00b37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,8 +32,8 @@ readme = "README.rst" license = {file = "LICENSE"} requires-python = ">=3.8" dependencies = [ - "scipy", - "numpy", + "scipy<2.0.0", + "numpy<2.0.0", "pandas~=2.2.0", "matplotlib>=3.6.1,<3.10.0", ]