Skip to content

Commit

Permalink
Fix logscale limit updates (#383)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
lukashergt authored Apr 24, 2024
1 parent 79c7bb6 commit 32769e8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.8.9'
__version__ = '2.8.10'
4 changes: 4 additions & 0 deletions anesthetic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 16 additions & 5 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,20 +526,31 @@ 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()
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
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'])
Expand Down

0 comments on commit 32769e8

Please sign in to comment.