Honour colorbar=False for colour-only corrplot glyphs - #31
Closed
fesanghary wants to merge 1 commit into
Closed
Conversation
`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>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
Author
|
Superseded by #34, which carries this colorbar fix along with two other corrplot rendering fixes (a clipped grid border, and a new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anupper/lowerhalf. Those panels keep their colorbar while every other method honours the flag.causalts/plotting/corrplot.py:has_color_onlyis 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 leftcl_pos="n"as the only way to get what you asked for.Reproduction (axes added to a fresh figure; 1 = colorbar drawn):
The fix
colorbar=Falsenow suppresses the colorbar for every method. The default is unchanged —colorbardefaults to True, socl_posstill resolves to"r"and every existing call that doesn't pass the flag renders identically.has_color_onlyexisted only for that guard and is removed.Regression tests
tests/test_plotting.pyhad no corrplot coverage at all. Added four cases: a smoke test,colorbar=Falseacross 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:
13 pass with the fix (9 before this PR).
One notebook figure changes
examples/plotting.ipynbcell 50 renders all seven glyphs withcolorbar=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, sincecolorandshadeare no longer squeezed by a colorbar the others don't have.Pre-existing bug found, deliberately not fixed here
examples/plotting.ipynbdoes not execute top to bottom — onmain, before this change. Cell 0 is an orphaned code cell sitting above the title and above the import cell, referencingplt,tp,gt1andnames1before any of them exist: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=Trueas 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