From cc331fdd65e8a2d25c5f6073e656f46330889393 Mon Sep 17 00:00:00 2001 From: mwaskom Date: Fri, 14 Jul 2017 15:34:07 -0400 Subject: [PATCH 1/5] Pass kde clipping kwarg to shade glyph --- seaborn/distributions.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/seaborn/distributions.py b/seaborn/distributions.py index c3ae5b96cd..12fa21ae31 100644 --- a/seaborn/distributions.py +++ b/seaborn/distributions.py @@ -305,12 +305,16 @@ def _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, # Draw the KDE plot and, optionally, shade ax.plot(x, y, color=color, label=label, **kwargs) - alpha = kwargs.get("alpha", 0.25) + shade_kws = dict( + facecolor=color, + alpha=kwargs.get("alpha", 0.25), + clip_on=kwargs.get("clip_on", True), + ) if shade: if vertical: - ax.fill_betweenx(y, 0, x, facecolor=color, alpha=alpha) + ax.fill_betweenx(y, 0, x, **shade_kws) else: - ax.fill_between(x, 0, y, facecolor=color, alpha=alpha) + ax.fill_between(x, 0, y, **shade_kws) # Set the density axis minimum to 0 if vertical: From 3ef0dc2ab1e55e1fffb116ed0777ff5b5a406c4b Mon Sep 17 00:00:00 2001 From: mwaskom Date: Fri, 14 Jul 2017 19:07:10 -0400 Subject: [PATCH 2/5] Use facecolor for different kdeplot fill --- seaborn/distributions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seaborn/distributions.py b/seaborn/distributions.py index 12fa21ae31..290bba5988 100644 --- a/seaborn/distributions.py +++ b/seaborn/distributions.py @@ -298,17 +298,20 @@ def _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, label = "_nolegend_" if label is None else label # Use the active color cycle to find the plot color + facecolor = kwargs.pop("facecolor", None) line, = ax.plot(x, y, **kwargs) color = line.get_color() line.remove() kwargs.pop("color", None) + facecolor = color if facecolor is None else facecolor # Draw the KDE plot and, optionally, shade ax.plot(x, y, color=color, label=label, **kwargs) shade_kws = dict( - facecolor=color, + facecolor=facecolor, alpha=kwargs.get("alpha", 0.25), clip_on=kwargs.get("clip_on", True), + zorder=kwargs.get("zorder", 1), ) if shade: if vertical: From 2c17cb829516d0a3856d870b12f25271efb296ce Mon Sep 17 00:00:00 2001 From: mwaskom Date: Fri, 14 Jul 2017 19:07:28 -0400 Subject: [PATCH 3/5] Add an example script to make a Joy Division plot --- examples/kde_joyplot.py | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/kde_joyplot.py diff --git a/examples/kde_joyplot.py b/examples/kde_joyplot.py new file mode 100644 index 0000000000..68d4f717e3 --- /dev/null +++ b/examples/kde_joyplot.py @@ -0,0 +1,43 @@ +""" +Overlapping KDEs ('Joy Division plot') +====================================== + + +""" +import numpy as np +import pandas as pd +import seaborn as sns +import matplotlib.pyplot as plt +sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)}) + +# Create the data +rs = np.random.RandomState(1979) +x = rs.randn(500) +g = np.tile(list("ABCDEFGHIJ"), 50) +df = pd.DataFrame(dict(x=x, g=g)) +m = df.g.map(ord) +df["x"] += m + +# Initialize the FacetGrid object +g = sns.FacetGrid(df, row="g", hue="g", aspect=12, size=.5, palette="tab10") + +# Draw the densities in a few steps +g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2) +g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2) +g.map(plt.axhline, y=0, lw=2, clip_on=False) + +# Define and use a simple function to label the plot in axes coordinates +def label(x, color, label): + ax = plt.gca() + ax.text(0, .2, label, fontweight="bold", color=color, + ha="left", va="center", transform=ax.transAxes) + +g.map(label, "x") + +# Set the subplots to overlap +g.fig.subplots_adjust(hspace=-.25) + +# Remove axes details that don't play will with overlap +g.set_titles("") +g.set(yticks=[]) +g.despine(bottom=True, left=True) From d7340199072e8f962af0992a148aa0581cc86d7f Mon Sep 17 00:00:00 2001 From: mwaskom Date: Fri, 14 Jul 2017 19:07:58 -0400 Subject: [PATCH 4/5] Remove tsplot example with functionality that will likely disappear --- examples/timeseries_bootstrapped.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 examples/timeseries_bootstrapped.py diff --git a/examples/timeseries_bootstrapped.py b/examples/timeseries_bootstrapped.py deleted file mode 100644 index 1b18804782..0000000000 --- a/examples/timeseries_bootstrapped.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Plotting timeseries data with bootstrap resampling -================================================== - -""" -import numpy as np -import seaborn as sns -sns.set(style="darkgrid", palette="Set2") - -# Create a noisy periodic dataset -sines = [] -rs = np.random.RandomState(8) -for _ in range(15): - x = np.linspace(0, 30 / 2, 30) - y = np.sin(x) + rs.normal(0, 1.5) + rs.normal(0, .3, 30) - sines.append(y) - -# Plot the average over replicates with bootstrap resamples -sns.tsplot(sines, err_style="boot_traces", n_boot=500) From 5256e854a9f8f10f60fcd7e8f841273f2a4d40ab Mon Sep 17 00:00:00 2001 From: mwaskom Date: Fri, 14 Jul 2017 21:06:36 -0400 Subject: [PATCH 5/5] Change joy division plot palette --- examples/kde_joyplot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/kde_joyplot.py b/examples/kde_joyplot.py index 68d4f717e3..f408505da0 100644 --- a/examples/kde_joyplot.py +++ b/examples/kde_joyplot.py @@ -19,7 +19,8 @@ df["x"] += m # Initialize the FacetGrid object -g = sns.FacetGrid(df, row="g", hue="g", aspect=12, size=.5, palette="tab10") +pal = sns.cubehelix_palette(10, rot=-.25, light=.7) +g = sns.FacetGrid(df, row="g", hue="g", aspect=12, size=.5, palette=pal) # Draw the densities in a few steps g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)