From c7ad0c956eb620bc3ff040121b0d8975b0a8f460 Mon Sep 17 00:00:00 2001 From: Abhimat Gautam Date: Wed, 24 Jun 2026 14:58:13 -0700 Subject: [PATCH 1/4] Support for rounding numbers in title --- src/corner/arviz_corner.py | 2 ++ src/corner/core.py | 17 +++++++++++++++-- src/corner/corner.py | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/corner/arviz_corner.py b/src/corner/arviz_corner.py index 1b17fac..42bf6e6 100644 --- a/src/corner/arviz_corner.py +++ b/src/corner/arviz_corner.py @@ -96,6 +96,7 @@ def arviz_corner( titles=None, show_titles=False, title_fmt=".2f", + title_round=None, title_kwargs=None, truths=None, truth_color="#4682b4", @@ -188,6 +189,7 @@ def arviz_corner( titles=titles, show_titles=show_titles, title_fmt=title_fmt, + title_round=title_round, title_kwargs=title_kwargs, truths=truths, truth_color=truth_color, diff --git a/src/corner/core.py b/src/corner/core.py index 9414782..d3684f3 100644 --- a/src/corner/core.py +++ b/src/corner/core.py @@ -44,6 +44,7 @@ def corner_impl( titles=None, show_titles=False, title_fmt=".2f", + title_round=None, title_kwargs=None, truths=None, truth_color="#4682b4", @@ -119,7 +120,15 @@ def corner_impl( assert ( len(title_fmt) == K ), "'title_fmt' should contain as many elements as data dimensions" - + + # Make title_round into a list if necessary, otherwise check length + if isinstance(title_round, int): + title_round = [title_round] * K + elif title_round is not None: + assert ( + len(title_fmt) == K + ), "'title_round' should contain as many elements as data dimensions" + # Make axes_scale into a list if necessary, otherwise check length if isinstance(axes_scale, str): axes_scale = [axes_scale] * K @@ -269,7 +278,11 @@ def corner_impl( x, title_quantiles, weights=weights ) q_m, q_p = q_mid - q_lo, q_hi - q_mid - + + # Round the titles if needed + if title_round is not None and title_round[i] is not None: + q_m, q_mid, q_p = round(q_m, title_round[i]), round(q_mid, title_round[i]), round(q_p, title_round[i]) + # Format the quantile display. fmt = "{{0:{0}}}".format(title_fmt[i]).format title = r"${{{0}}}_{{-{1}}}^{{+{2}}}$" diff --git a/src/corner/corner.py b/src/corner/corner.py index 46b609f..9dd1ddf 100644 --- a/src/corner/corner.py +++ b/src/corner/corner.py @@ -32,6 +32,7 @@ def corner( show_titles=False, title_quantiles=None, title_fmt=".2f", + title_round=None, title_kwargs=None, truths=None, truth_color="#4682b4", @@ -149,10 +150,19 @@ def corner( quantiles is `None`, in which case it defaults to [0.16,0.5,0.84] title_fmt : string or iterable (ndim,) - The format string for the quantiles given in titles for eachimension. + The format string for the quantiles given in titles for each dimension. If you explicitly set ``show_titles=True`` and ``title_fmt=None``, the labels will be shown as the titles. (default: ``.2f``) - + + title_round : int or iterable (ndim,) + Specifies how many digits to round to after the decimal point for each + dimension. Use negative values for rounding to left of decimal point. + Uses python `round() function for rounding. + If rounding right of decimal point, use ``title_fmt`` instead + since `round()` can give unexpected behavior for floats. + Specify `None` for any dimension to not be formatted with `round()`. + (default: `None`) + title_kwargs : dict Any extra keyword arguments to send to the `set_title` command. @@ -261,6 +271,7 @@ def corner( show_titles=show_titles, title_quantiles=title_quantiles, title_fmt=title_fmt, + title_round=title_round, title_kwargs=title_kwargs, truths=truths, truth_color=truth_color, @@ -293,6 +304,7 @@ def corner( show_titles=show_titles, title_quantiles=title_quantiles, title_fmt=title_fmt, + title_round=title_round, title_kwargs=title_kwargs, truths=truths, truth_color=truth_color, From bf782e532ee349b4b773653af49d355f49b0944e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 22:05:10 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/corner/core.py | 14 +++++++++----- src/corner/corner.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/corner/core.py b/src/corner/core.py index d3684f3..52f15e4 100644 --- a/src/corner/core.py +++ b/src/corner/core.py @@ -120,7 +120,7 @@ def corner_impl( assert ( len(title_fmt) == K ), "'title_fmt' should contain as many elements as data dimensions" - + # Make title_round into a list if necessary, otherwise check length if isinstance(title_round, int): title_round = [title_round] * K @@ -128,7 +128,7 @@ def corner_impl( assert ( len(title_fmt) == K ), "'title_round' should contain as many elements as data dimensions" - + # Make axes_scale into a list if necessary, otherwise check length if isinstance(axes_scale, str): axes_scale = [axes_scale] * K @@ -278,11 +278,15 @@ def corner_impl( x, title_quantiles, weights=weights ) q_m, q_p = q_mid - q_lo, q_hi - q_mid - + # Round the titles if needed if title_round is not None and title_round[i] is not None: - q_m, q_mid, q_p = round(q_m, title_round[i]), round(q_mid, title_round[i]), round(q_p, title_round[i]) - + q_m, q_mid, q_p = ( + round(q_m, title_round[i]), + round(q_mid, title_round[i]), + round(q_p, title_round[i]), + ) + # Format the quantile display. fmt = "{{0:{0}}}".format(title_fmt[i]).format title = r"${{{0}}}_{{-{1}}}^{{+{2}}}$" diff --git a/src/corner/corner.py b/src/corner/corner.py index 9dd1ddf..f919fc4 100644 --- a/src/corner/corner.py +++ b/src/corner/corner.py @@ -153,7 +153,7 @@ def corner( The format string for the quantiles given in titles for each dimension. If you explicitly set ``show_titles=True`` and ``title_fmt=None``, the labels will be shown as the titles. (default: ``.2f``) - + title_round : int or iterable (ndim,) Specifies how many digits to round to after the decimal point for each dimension. Use negative values for rounding to left of decimal point. @@ -162,7 +162,7 @@ def corner( since `round()` can give unexpected behavior for floats. Specify `None` for any dimension to not be formatted with `round()`. (default: `None`) - + title_kwargs : dict Any extra keyword arguments to send to the `set_title` command. From 05b44c938587ee9fcdfbf44668d970de4e266f65 Mon Sep 17 00:00:00 2001 From: Abhimat Gautam Date: Wed, 24 Jun 2026 19:53:46 -0700 Subject: [PATCH 3/4] Check for symmetric error bars --- src/corner/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corner/core.py b/src/corner/core.py index d3684f3..e1c2365 100644 --- a/src/corner/core.py +++ b/src/corner/core.py @@ -286,8 +286,15 @@ def corner_impl( # Format the quantile display. fmt = "{{0:{0}}}".format(title_fmt[i]).format title = r"${{{0}}}_{{-{1}}}^{{+{2}}}$" + + # Check for symmetric errorbars + if fmt(q_m) == fmt(q_p): + title = r"${{{0}}}\pm{{{1}}}$" + title = title.format(fmt(q_mid), fmt(q_m), fmt(q_p)) - + + + # Add in the column name if it's given. if titles is not None: title = "{0} = {1}".format(titles[i], title) From 853e4539672c56b068f6b8ac3ff6f4c1ebb312aa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 02:56:30 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/corner/core.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/corner/core.py b/src/corner/core.py index 589e8ac..39c5b63 100644 --- a/src/corner/core.py +++ b/src/corner/core.py @@ -290,15 +290,13 @@ def corner_impl( # Format the quantile display. fmt = "{{0:{0}}}".format(title_fmt[i]).format title = r"${{{0}}}_{{-{1}}}^{{+{2}}}$" - + # Check for symmetric errorbars if fmt(q_m) == fmt(q_p): title = r"${{{0}}}\pm{{{1}}}$" - + title = title.format(fmt(q_mid), fmt(q_m), fmt(q_p)) - - - + # Add in the column name if it's given. if titles is not None: title = "{0} = {1}".format(titles[i], title)