Skip to content
Closed
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

### Fixed

* `corrplot(..., colorbar=False)` was ignored whenever the glyph method drew
colour only (`method="color"` or `"shade"`, or either as an `upper`/`lower`
half) — those panels kept their colorbar while every other method honoured the
flag. Callers had to reach for `cl_pos="n"` instead. `colorbar=False` now
suppresses the colorbar for every method.
* Documentation: the "New in v0.26" banner linked to the example notebook with a
path relative to the site root, but the banner renders on every page — from
anything below the root (`examples/`, `api/`, `getting_started/`) it resolved to
Expand Down
14 changes: 5 additions & 9 deletions causalts/plotting/corrplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,13 @@ def corrplot(
tl_pos = "lt" # left + top for upper triangle

# --- Default cl_pos ---
color_only_methods = {"color", "shade"}
active_methods = {method}
if upper is not None:
active_methods.add(upper)
if lower is not None:
active_methods.add(lower)
has_color_only = bool(active_methods & color_only_methods)

# ``colorbar=False`` suppresses the colorbar for every glyph method. It used
# to be ignored for the colour-only methods ('color', 'shade') on the theory
# that they are unreadable without a scale -- but that silently overrode an
# explicit argument, so the caller had to reach for ``cl_pos='n'`` instead.
if cl_pos is None:
cl_pos = "r"
if not colorbar and not has_color_only:
if not colorbar:
cl_pos = "n"

# --- Default grid_color ---
Expand Down
50 changes: 25 additions & 25 deletions examples/plotting.ipynb

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,46 @@ def test_compare_graphs_smoke():
g2 = g.copy()
g2[2, 0, 1] = 1
compare_graphs(g, g2, var_names=["X", "Y", "Z"])


def _make_frame():
import pandas as pd

rng = np.random.default_rng(0)
return pd.DataFrame(rng.standard_normal((60, 4)), columns=list("ABCD"))


def _extra_axes(**kwargs):
"""Axes added to a fresh figure by one corrplot call (1 = colorbar drawn)."""
import matplotlib.pyplot as plt

from causalts.plotting import corrplot

fig, ax = plt.subplots()
before = len(fig.axes)
corrplot(_make_frame(), fig_ax=(fig, ax), **kwargs)
added = len(fig.axes) - before
plt.close(fig)
return added


def test_corrplot_smoke():
from causalts.plotting import corrplot

corrplot(_make_frame())


def test_corrplot_colorbar_false_suppresses_for_every_method():
# Regression: 'color' and 'shade' encode magnitude in the fill alone and
# used to draw a colorbar even when the caller passed colorbar=False.
for method in ("circle", "square", "ellipse", "number", "color", "shade", "pie"):
assert _extra_axes(method=method, colorbar=False) == 0, method


def test_corrplot_colorbar_default_still_draws():
for method in ("circle", "color", "shade"):
assert _extra_axes(method=method) == 1, method


def test_corrplot_colorbar_false_with_color_only_half():
assert _extra_axes(upper="color", lower="number", colorbar=False) == 0