Skip to content

Fix FacetGrid.refline picking up hue_kws aesthetics like marker - #3979

Open
aryansk wants to merge 1 commit into
mwaskom:masterfrom
aryansk:fix/3973-refline-marker
Open

aryansk wants to merge 1 commit into
mwaskom:masterfrom
aryansk:fix/3973-refline-marker

Conversation

@aryansk

@aryansk aryansk commented Aug 15, 2026

Copy link
Copy Markdown

Fixes

Fixes #3973

Problem

lmplot registers a marker aesthetic in FacetGrid.hue_kws (even when there is no hue mapping), and FacetGrid.map unconditionally injects every hue_kws entry into the mapped function. Since FacetGrid.refline draws its reference lines via self.map(plt.axvline / plt.axhline, ...), the marker rides along into a function that never asked for it, and axvline/axhline draw a dot at both ends of the reference line:

import seaborn as sns
import pandas as pd

df = pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [0.0, 1.0, 2.0]})
g = sns.lmplot(df, x="x", y="y")
g.refline(x=0, y=0)   # gray dots appear on both ends of the line

Change

Draw the reference lines directly on each facet axis instead of routing them through map(), so hue_kws aesthetics (markers, etc.) are never injected into axvline/axhline. The color=None hue-mapping behavior is preserved through _facet_color, which now resolves the per-hue palette color.

Validation

  • New regression test test_refline_no_hue_kws asserts:
    • reference lines from lmplot().refline() carry no marker;
    • with a hue mapping, refline(color=None) still draws each line in its hue's palette color.
  • tests/test_axisgrid.py: 124 passed.
  • tests/test_regression.py: 52 passed, 9 skipped (unrelated).

Note: this change was prepared with AI assistance; the root-cause analysis and the approach (bypass map() in refline, keep map()'s hue_kws injection intact for data-mapped functions) were reviewed and validated locally against the seaborn test suite.

lmplot registers a marker in ``hue_kws`` even without a hue mapping, and
``FacetGrid.map`` unconditionally injects those aesthetics into whatever
function it is given. refline was calling ``self.map(plt.axvline, ...)``,
so reference lines ended up with a ``marker`` attribute and drew dots at
both ends.

Draw the reference lines directly on each facet axis instead, preserving
the hue-mapped color behavior via ``_facet_color`` when ``color=None``.

Closes GH#3973
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.

lmplot with refline produces unexpected markers on both ends of the lines

1 participant