Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 tick minimum also for logscale #372

Merged
merged 11 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.3
:Version: 2.8.4
: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.3'
__version__ = '2.8.4'
11 changes: 10 additions & 1 deletion anesthetic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def plot_2d(self, axes=None, *args, **kwargs):
else:
ax.plot([], [])

axes._set_logticks()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried setting the log ticks in the same place where we generally deal with tick locations, but plot_2d overwrites these locations, so this call at the end of plot_2d is needed...


return axes

plot_2d_default_kinds = {
Expand Down
19 changes: 19 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,25 @@ def test_plot_logscale_2d(kind):
assert ax.twin.get_yscale() == 'linear'


def test_logscale_ticks():
np.random.seed(42)
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)
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)])
Expand Down
Loading