Skip to content

Honour colorbar=False for colour-only corrplot glyphs - #31

Closed
fesanghary wants to merge 1 commit into
mainfrom
fix/corrplot-colorbar-false
Closed

Honour colorbar=False for colour-only corrplot glyphs#31
fesanghary wants to merge 1 commit into
mainfrom
fix/corrplot-colorbar-false

Conversation

@fesanghary

Copy link
Copy Markdown
Contributor

Found while writing the beginner's-guide corrplot figure in #30, where I had to work around it.

The bug

corrplot(..., colorbar=False) is silently ignored whenever the glyph method encodes magnitude in the fill — method="color" or "shade", or either one as an upper/lower half. Those panels keep their colorbar while every other method honours the flag.

causalts/plotting/corrplot.py:

if not colorbar and not has_color_only:
    cl_pos = "n"

has_color_only is True for those methods, so the condition never fires. The intent was presumably that a colour-only plot is hard to read without a scale — defensible as a default, but it overrode an explicit argument with no warning, and left cl_pos="n" as the only way to get what you asked for.

Reproduction (axes added to a fresh figure; 1 = colorbar drawn):

method=circle   colorbar=False -> 0
method=color    colorbar=False -> 1   <-- ignored
method=shade    colorbar=False -> 1   <-- ignored
method=number   colorbar=False -> 0

The fix

colorbar=False now suppresses the colorbar for every method. The default is unchanged — colorbar defaults to True, so cl_pos still resolves to "r" and every existing call that doesn't pass the flag renders identically. has_color_only existed only for that guard and is removed.

Regression tests

tests/test_plotting.py had no corrplot coverage at all. Added four cases: a smoke test, colorbar=False across all seven glyph methods, the default still drawing a colorbar, and a mixed upper/lower with one colour-only half.

Verified red-then-green — reverting only the corrplot change fails two of them:

FAILED test_corrplot_colorbar_false_suppresses_for_every_method
FAILED test_corrplot_colorbar_false_with_color_only_half
2 failed, 2 passed

13 pass with the fix (9 before this PR).

One notebook figure changes

examples/plotting.ipynb cell 50 renders all seven glyphs with colorbar=False, so its committed figure showed the bug directly: five panels without a colorbar, two with. Re-executed and spliced that one cell — the other 63 keep their committed bytes. The panels are now uniformly sized, since color and shade are no longer squeezed by a colorbar the others don't have.

Pre-existing bug found, deliberately not fixed here

examples/plotting.ipynb does not execute top to bottom — on main, before this change. Cell 0 is an orphaned code cell sitting above the title and above the import cell, referencing plt, tp, gt1 and names1 before any of them exist:

cell 0: NameError: name 'plt' is not defined

So "Run All" fails on the very first cell for any reader. Confirmed on a pristine checkout, so it is not from this PR. Regenerating cell 50 needed allow_errors=True as a result; cell 50 itself runs clean because the imports land in cell 2.

The cell looks misplaced rather than wrong — it belongs somewhere in the target-node section. Left for a separate PR since fixing it properly means deciding where it goes, and moving it would re-render unrelated figures. Happy to do it next if you want.

🤖 Generated with Claude Code

`corrplot(..., colorbar=False)` was silently ignored whenever the glyph method
encoded magnitude in the fill -- `method="color"` or `"shade"`, or either as an
`upper`/`lower` half. Those panels kept their colorbar while every other method
honoured the flag, so callers had to reach for `cl_pos="n"` instead.

The guard read:

    if not colorbar and not has_color_only:
        cl_pos = "n"

`has_color_only` is True for those methods, so the condition never fired. The
intent was presumably that a colour-only plot is unreadable without a scale --
defensible as a *default*, but it overrode an explicit argument with no warning.

`colorbar=False` now suppresses the colorbar for every method. The default is
unchanged: `colorbar` defaults to True, so `cl_pos` still resolves to "r" and
every existing call that does not pass the flag renders identically.
`has_color_only` existed solely for that guard and is now gone.

## Regression tests

`tests/test_plotting.py` had no corrplot coverage at all. Added four cases: a
smoke test, `colorbar=False` across all seven glyph methods, the default still
drawing a colorbar, and a mixed upper/lower with one colour-only half. Verified
red-then-green -- reverting only the corrplot change fails two of them:

    FAILED test_corrplot_colorbar_false_suppresses_for_every_method
    FAILED test_corrplot_colorbar_false_with_color_only_half

## Notebook figure regenerated

`examples/plotting.ipynb` cell 50 renders all seven glyphs with
`colorbar=False`, so its committed figure showed the bug directly: five panels
without a colorbar and two with. Re-executed and spliced that one cell; the
other 63 keep their committed bytes.

## Pre-existing, not fixed here

`examples/plotting.ipynb` does not execute top to bottom, on main and before
this change. Cell 0 is an orphaned code cell sitting above the title and the
import cell, referencing `plt`, `tp`, `gt1` and `names1` before any of them
exist, so "Run All" fails immediately. Regenerating cell 50 therefore needed
`allow_errors=True`; cell 50 itself runs clean, as the imports land in cell 2.
Worth a separate fix -- the cell looks misplaced rather than wrong.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@fesanghary
fesanghary requested a review from a team as a code owner August 17, 2026 22:19
@github-actions

Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@fesanghary

Copy link
Copy Markdown
Contributor Author

Superseded by #34, which carries this colorbar fix along with two other corrplot rendering fixes (a clipped grid border, and a new diag='glyph' mode for directed matrices). The tests added here were adopted verbatim in #34 — they loop over all seven glyph methods, which is strictly stronger coverage than what I'd written. Closing in favour of that PR.

@fesanghary fesanghary closed this Aug 20, 2026
@fesanghary
fesanghary deleted the fix/corrplot-colorbar-false branch August 22, 2026 23:49
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