Skip to content

Commit 15015bc

Browse files
committed
Fix unfilled kdeplot cmap regression
1 parent c412ddf commit 15015bc

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

doc/whatsnew/v0.12.1.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ v0.12.1 (Unreleased)
1010

1111
- |Fix| Fixed a bug that caused an exception when more than two layers with the same mappings were added (:pr:`3055`).
1212

13+
- |Fix| Fixed a regression in :func:`kdeplot` where passing `cmap` for an unfilled bivariate plot would raise an exception (:pr:`3065`).
14+
1315
- |Build| Seaborn no longer contains doctest-style examples, simplifying the testing infrastructure (:pr:`3034`).

seaborn/distributions.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,14 +1130,6 @@ def plot_bivariate_density(
11301130
for k, d in densities.items()
11311131
}
11321132

1133-
# Get a default single color from the attribute cycle
1134-
if self.ax is None:
1135-
default_color = "C0" if color is None else color
1136-
else:
1137-
scout, = self.ax.plot([], color=color)
1138-
default_color = scout.get_color()
1139-
scout.remove()
1140-
11411133
# Define the coloring of the contours
11421134
if "hue" in self.variables:
11431135
for param in ["cmap", "colors"]:
@@ -1150,10 +1142,10 @@ def plot_bivariate_density(
11501142
# Work out a default coloring of the contours
11511143
coloring_given = set(contour_kws) & {"cmap", "colors"}
11521144
if fill and not coloring_given:
1153-
cmap = self._cmap_from_color(default_color)
1145+
cmap = self._cmap_from_color(color)
11541146
contour_kws["cmap"] = cmap
11551147
if not fill and not coloring_given:
1156-
contour_kws["colors"] = [default_color]
1148+
contour_kws["colors"] = [color]
11571149

11581150
# Use our internal colormap lookup
11591151
cmap = contour_kws.pop("cmap", None)

seaborn/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def _default_color(method, hue, color, kws):
100100

101101
elif method.__name__ == "plot":
102102

103-
scout, = method([], [], scalex=False, scaley=False, **kws)
103+
color = _normalize_kwargs(kws, mpl.lines.Line2D).get("color")
104+
scout, = method([], [], scalex=False, scaley=False, color=color)
104105
color = scout.get_color()
105106
scout.remove()
106107

tests/test_distributions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,15 @@ def test_contour_line_colors(self, long_df):
10601060
for c in ax.collections:
10611061
assert_colors_equal(get_contour_color(c), color)
10621062

1063+
def test_contour_line_cmap(self, long_df):
1064+
1065+
color_list = color_palette("Blues", 12)
1066+
cmap = mpl.colors.ListedColormap(color_list)
1067+
ax = kdeplot(data=long_df, x="x", y="y", cmap=cmap)
1068+
for c in ax.collections:
1069+
color = to_rgb(get_contour_color(c).squeeze())
1070+
assert color in color_list
1071+
10631072
def test_contour_fill_colors(self, long_df):
10641073

10651074
n = 6

0 commit comments

Comments
 (0)