From 2faed7b4c855f6176381f9e546da7be55727eccb Mon Sep 17 00:00:00 2001 From: Samuel Hinton Date: Fri, 30 Oct 2020 11:19:10 +1000 Subject: [PATCH] Fixes #83 Creating new formatters per x and y axis instead of a global formatter --- README.md | 4 +++- chainconsumer/chainconsumer.py | 2 +- chainconsumer/plotter.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 70cb3ee7..f82bf932 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,10 @@ post, it can be solved by explicitly install the `matplotlib` dependency `dvipng ### Update History -##### 0.31.2, 0.31.3 +##### 0.32.0 +* Fixing matplotlib axis formatter issue. +##### 0.31.2, 0.31.3 * Conda-forge updates ##### 0.31.1 diff --git a/chainconsumer/chainconsumer.py b/chainconsumer/chainconsumer.py index 66ef5eea..c987c39a 100644 --- a/chainconsumer/chainconsumer.py +++ b/chainconsumer/chainconsumer.py @@ -20,7 +20,7 @@ class ChainConsumer(object): """ - __version__ = "0.31.3" + __version__ = "0.32.0" def __init__(self): logging.basicConfig(level=logging.INFO) diff --git a/chainconsumer/plotter.py b/chainconsumer/plotter.py index 2410b141..9f413a57 100644 --- a/chainconsumer/plotter.py +++ b/chainconsumer/plotter.py @@ -445,7 +445,7 @@ def plot_walks( if i == 0 and plot_posterior: for chain in chains: if chain.posterior is not None: - self._plot_walk(ax, "$\log(P)$", chain.posterior - chain.posterior.max(), convolve=convolve, color=chain.config["color"]) + self._plot_walk(ax, r"$\log(P)$", chain.posterior - chain.posterior.max(), convolve=convolve, color=chain.config["color"]) else: if log_weight is None: log_weight = np.any([chain.weights.mean() < 0.1 for chain in chains]) @@ -939,9 +939,6 @@ def _get_figure(self, all_parameters, flip, figsize=(5, 5), external_extents=Non fig, axes = plt.subplots(n, n, figsize=figsize, squeeze=False, gridspec_kw=gridspec_kw) fig.subplots_adjust(left=0.1, right=0.95, top=0.95, bottom=0.1, wspace=0.05 * spacing, hspace=0.05 * spacing) - formatter = ScalarFormatter(useOffset=False) - formatter.set_powerlimits((-3, 4)) - extents = self._get_custom_extents(all_parameters, chains, external_extents) if plot_hists: @@ -953,6 +950,11 @@ def _get_figure(self, all_parameters, flip, figsize=(5, 5), external_extents=Non for i, p1 in enumerate(params1): for j, p2 in enumerate(params2): ax = axes[i, j] + formatter_x = ScalarFormatter(useOffset=True) + formatter_x.set_powerlimits((-3, 4)) + formatter_y = ScalarFormatter(useOffset=True) + formatter_y.set_powerlimits((-3, 4)) + display_x_ticks = False display_y_ticks = False if i < j: @@ -1001,7 +1003,7 @@ def _get_figure(self, all_parameters, flip, figsize=(5, 5), external_extents=Non _ = [l.set_fontsize(tick_font_size) for l in ax.get_xticklabels()] if not logx: ax.xaxis.set_major_locator(MaxNLocator(max_ticks, prune="lower")) - ax.xaxis.set_major_formatter(formatter) + ax.xaxis.set_major_formatter(formatter_x) else: ax.xaxis.set_major_locator(LogLocator(numticks=max_ticks)) else: @@ -1012,7 +1014,7 @@ def _get_figure(self, all_parameters, flip, figsize=(5, 5), external_extents=Non _ = [l.set_fontsize(tick_font_size) for l in ax.get_yticklabels()] if not logy: ax.yaxis.set_major_locator(MaxNLocator(max_ticks, prune="lower")) - ax.yaxis.set_major_formatter(formatter) + ax.yaxis.set_major_formatter(formatter_y) else: ax.yaxis.set_major_locator(LogLocator(numticks=max_ticks)) else: