Skip to content

Commit

Permalink
test that limits get accurately updated by successive plots with logs…
Browse files Browse the repository at this point in the history
…cale axes, adjusting to new data limits, see issue #381
  • Loading branch information
lukashergt committed Apr 23, 2024
1 parent 79c7bb6 commit 82c9262
Showing 1 changed file with 16 additions and 5 deletions.
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 82c9262

Please sign in to comment.