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..39c5b63 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", @@ -120,6 +121,14 @@ def corner_impl( 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 @@ -270,9 +279,22 @@ def corner_impl( ) 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}}}$" + + # 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. diff --git a/src/corner/corner.py b/src/corner/corner.py index 46b609f..f919fc4 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,