From b59da430b1ff7fe89546d1a1d8d2c3c63bfc5fef Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 15 Mar 2024 17:18:03 -0700 Subject: [PATCH 01/10] add test for minimum of 2 ticks for logscale --- tests/test_samples.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_samples.py b/tests/test_samples.py index a40b85e5..02215e24 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -514,6 +514,28 @@ def test_plot_logscale_2d(kind): assert ax.twin.get_yscale() == 'linear' +def test_logscale_ticks(): + np.random.seed(42) + plt.rcParams['figure.figsize'] = 3, 3 + plt.rcParams['font.size'] = 10 + + ndim = 3 + data = np.exp(10 * np.random.randn(200, ndim)) + 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(): + if ax is not None: + xlims = ax.get_xlim() + xticks = ax.get_xticks() + assert np.sum((xticks > xlims[0]) & (xticks < xlims[1])) > 1 + ylims = ax.get_ylim() + yticks = ax.get_yticks() + assert np.sum((yticks > ylims[0]) & (yticks < ylims[1])) > 1 + + @pytest.mark.parametrize('k', ['hist_1d', 'hist']) @pytest.mark.parametrize('b', ['scott', 10, np.logspace(-3, 0, 20)]) @pytest.mark.parametrize('r', [None, (1e-5, 1)]) From 0262e964c8796c8684c16c2a7fe14913da2093da Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 15 Mar 2024 17:28:27 -0700 Subject: [PATCH 02/10] bump version to 2.8.2 --- README.rst | 2 +- anesthetic/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 6a6ad009..72289ae4 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.1 +:Version: 2.8.2 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 80e22f7a..964a32ab 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.8.1' +__version__ = '2.8.2' From f719f0d2ba2c464d45078f6b0933034dc482b2e1 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 18 Mar 2024 15:56:12 -0700 Subject: [PATCH 03/10] create `_set_logticks` method that ensures at least 2 ticks per log axis, unfortunately appears to have to be called after every call to `plot_2d` --- anesthetic/plot.py | 11 ++++++++++- anesthetic/samples.py | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/anesthetic/plot.py b/anesthetic/plot.py index 05f3fa27..561fa2da 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -18,7 +18,7 @@ from matplotlib.axes import Axes import matplotlib.cbook as cbook import matplotlib.lines as mlines -from matplotlib.ticker import MaxNLocator, AutoMinorLocator +from matplotlib.ticker import MaxNLocator, AutoMinorLocator, LogLocator from matplotlib.colors import LinearSegmentedColormap from matplotlib.transforms import Affine2D from anesthetic.utils import nest_level @@ -388,6 +388,15 @@ def _set_scale(self): if y in self._logy: ax.set_yscale('log') + def _set_logticks(self): + for y, rows in self.iterrows(): + for x, ax in rows.items(): + if ax is not None: + if x in self._logx: + ax.xaxis.set_major_locator(LogLocator(numticks=3)) + if y in self._logy: + ax.yaxis.set_major_locator(LogLocator(numticks=3)) + @staticmethod def _set_labels(axes, labels, **kwargs): all_params = list(axes.columns) + list(axes.index) diff --git a/anesthetic/samples.py b/anesthetic/samples.py index d2c95317..0ddd67a7 100644 --- a/anesthetic/samples.py +++ b/anesthetic/samples.py @@ -355,6 +355,8 @@ def plot_2d(self, axes=None, *args, **kwargs): else: ax.plot([], []) + axes._set_logticks() + return axes plot_2d_default_kinds = { From eba68c8ef5baf7f454461a056ad75f6b1deb980a Mon Sep 17 00:00:00 2001 From: lukashergt Date: Mon, 18 Mar 2024 23:23:13 -0700 Subject: [PATCH 04/10] try to fix `test_BarPlot` which actually should be unrelated to recent changes but for some reason acts up --- tests/test_weighted_pandas.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index 474daa23..3bc3aea4 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -857,8 +857,10 @@ def test_AreaPlot(mcmc_df, mcmc_wdf): def test_BarPlot(mcmc_df, mcmc_wdf): - axes_bar = mcmc_wdf[5:10].plot.bar() - axes_barh = mcmc_wdf[5:10].plot.barh() + _, ax1 = plt.subplots(figsize=(5, 5)) + _, ax2 = plt.subplots(figsize=(5, 5)) + axes_bar = mcmc_wdf[5:10].plot.bar(ax=ax1) + axes_barh = mcmc_wdf[5:10].plot.barh(ax=ax2) assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) From 50afec052b0b2c640120be6aa55be7a2d1dbd438 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Tue, 19 Mar 2024 15:49:49 -0700 Subject: [PATCH 05/10] try alternative fix for `test_BarPlot` making use of `iloc` --- tests/test_weighted_pandas.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index 3bc3aea4..443e5038 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -857,10 +857,8 @@ def test_AreaPlot(mcmc_df, mcmc_wdf): def test_BarPlot(mcmc_df, mcmc_wdf): - _, ax1 = plt.subplots(figsize=(5, 5)) - _, ax2 = plt.subplots(figsize=(5, 5)) - axes_bar = mcmc_wdf[5:10].plot.bar(ax=ax1) - axes_barh = mcmc_wdf[5:10].plot.barh(ax=ax2) + axes_bar = mcmc_wdf.iloc[5:10].plot.bar() + axes_barh = mcmc_wdf.iloc[5:10].plot.barh() assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) From 2a34beb449dd5a60fc84117a52bd7a1eb1db4aa3 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 22 Mar 2024 13:13:53 -0700 Subject: [PATCH 06/10] Revert "try alternative fix for `test_BarPlot` making use of `iloc`" This reverts commit 50afec052b0b2c640120be6aa55be7a2d1dbd438. --- tests/test_weighted_pandas.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index 443e5038..3bc3aea4 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -857,8 +857,10 @@ def test_AreaPlot(mcmc_df, mcmc_wdf): def test_BarPlot(mcmc_df, mcmc_wdf): - axes_bar = mcmc_wdf.iloc[5:10].plot.bar() - axes_barh = mcmc_wdf.iloc[5:10].plot.barh() + _, ax1 = plt.subplots(figsize=(5, 5)) + _, ax2 = plt.subplots(figsize=(5, 5)) + axes_bar = mcmc_wdf[5:10].plot.bar(ax=ax1) + axes_barh = mcmc_wdf[5:10].plot.barh(ax=ax2) assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) From 5a5cd11ad05c9903b7f4ea17b2e5dd670d11eca2 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 22 Mar 2024 13:20:15 -0700 Subject: [PATCH 07/10] Revert "try to fix `test_BarPlot` which actually should be unrelated to recent changes but for some reason acts up" This reverts commit eba68c8ef5baf7f454461a056ad75f6b1deb980a. --- tests/test_weighted_pandas.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index 3bc3aea4..474daa23 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -857,10 +857,8 @@ def test_AreaPlot(mcmc_df, mcmc_wdf): def test_BarPlot(mcmc_df, mcmc_wdf): - _, ax1 = plt.subplots(figsize=(5, 5)) - _, ax2 = plt.subplots(figsize=(5, 5)) - axes_bar = mcmc_wdf[5:10].plot.bar(ax=ax1) - axes_barh = mcmc_wdf[5:10].plot.barh(ax=ax2) + axes_bar = mcmc_wdf[5:10].plot.bar() + axes_barh = mcmc_wdf[5:10].plot.barh() assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) From 3bcc92d9295ec4df7975cf054162d3ff9f1f8559 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 22 Mar 2024 13:23:11 -0700 Subject: [PATCH 08/10] remove comparison of bar yticks with barh xticks, since this test is not robust across different figure sizes, where often the yaxis is shorter than the xaxis, which caused failures in some CI settings --- tests/test_weighted_pandas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index 474daa23..ac9c48d4 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -860,7 +860,6 @@ def test_BarPlot(mcmc_df, mcmc_wdf): axes_bar = mcmc_wdf[5:10].plot.bar() axes_barh = mcmc_wdf[5:10].plot.barh() assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) - assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) def test_PiePlot(mcmc_df, mcmc_wdf): From d0148805e3e3477ae7bf148e863ce64c86e5bf8c Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 22 Mar 2024 13:42:17 -0700 Subject: [PATCH 09/10] remove `rcParams` modification from `test_logscale_ticks`, as this messes with other tests, make the test work with default settings instead --- tests/test_samples.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_samples.py b/tests/test_samples.py index 02215e24..6190ac4f 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -516,10 +516,7 @@ def test_plot_logscale_2d(kind): def test_logscale_ticks(): np.random.seed(42) - plt.rcParams['figure.figsize'] = 3, 3 - plt.rcParams['font.size'] = 10 - - ndim = 3 + ndim = 5 data = np.exp(10 * np.random.randn(200, ndim)) params = [f'a{i}' for i in range(ndim)] fig, axes = make_2d_axes(params, logx=params, logy=params, upper=False) From 3bef1ec282cc60dc4905c010e834d9f7915d7c1f Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 22 Mar 2024 13:44:18 -0700 Subject: [PATCH 10/10] Revert "remove comparison of bar yticks with barh xticks, since this test is not robust across different figure sizes, where often the yaxis is shorter than the xaxis, which caused failures in some CI settings" This reverts commit 3bcc92d9295ec4df7975cf054162d3ff9f1f8559. --- tests/test_weighted_pandas.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_weighted_pandas.py b/tests/test_weighted_pandas.py index ac9c48d4..474daa23 100644 --- a/tests/test_weighted_pandas.py +++ b/tests/test_weighted_pandas.py @@ -860,6 +860,7 @@ def test_BarPlot(mcmc_df, mcmc_wdf): axes_bar = mcmc_wdf[5:10].plot.bar() axes_barh = mcmc_wdf[5:10].plot.barh() assert_array_equal(axes_bar.get_xticks(), axes_barh.get_yticks()) + assert_array_equal(axes_bar.get_yticks(), axes_barh.get_xticks()) def test_PiePlot(mcmc_df, mcmc_wdf):