Skip to content

Use a real newline when wrapping quantiles under the title - #341

Open
uttam12331 wants to merge 1 commit into
dfm:mainfrom
uttam12331:fix-wrap-title-newline
Open

Use a real newline when wrapping quantiles under the title#341
uttam12331 wants to merge 1 commit into
dfm:mainfrom
uttam12331:fix-wrap-title-newline

Conversation

@uttam12331

Copy link
Copy Markdown

Summary

The wrap_title_quantiles=True option is supposed to place the quantile summary on a separate line below the parameter name (per its docstring). But the title is built with an escaped backslash:

if wrap_title_quantiles:
    title = "{0} =\n{1}".format(titles[i], title)   # "\n" -> literal backslash-n
else:
    title = "{0} = {1}".format(titles[i], title)

In a normal (non-raw) string, "\n" is a literal backslash followed by n, not a newline. So the feature never wraps — it injects the visible characters \n into the title.

Reproduction

import numpy as np, corner
data = np.random.randn(100, 2)
fig = corner.corner(data, labels=["alpha", "beta"], show_titles=True,
                    title_fmt=".2f", wrap_title_quantiles=True)
# title text is e.g.  'alpha =\n${-0.05}_{-0.98}^{+1.06}$'
#   -> the literal two characters "\n", no real line break

Fix

-                        title = "{0} =\n{1}".format(titles[i], title)
+                        title = "{0} =\n{1}".format(titles[i], title)

Tests

Added test_wrap_title_quantiles, which asserts a title contains a real newline when wrap_title_quantiles=True and none when it's False. It fails on the current code (literal \n, no newline character) and passes with the fix.

`wrap_title_quantiles=True` built the title with "{0} =\n{1}", where the
escaped backslash makes "\n" a literal two-character sequence rather than a
newline, so the quantile summary was never placed on a separate line as the
parameter's docstring promises -- instead a literal "\n" appeared in the
title text.

Use "{0} =\n{1}" so the summary wraps onto a new line, and add a regression
test asserting the title contains a real newline only when wrapping is on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant