Skip to content
Open
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: 2 additions & 0 deletions src/corner/arviz_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions src/corner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion src/corner/corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down