Shade / Palette Based Windshield Kit
I'm trying to create a shape similar to this one from the seabed documentation, but with the edgecolor stripplot determined by the hue. This is my attempt:
import seaborn as sns
df = sns.load_dataset("tips")
ax = sns.stripplot(x="sex", y="tip", hue="day", data=df, jitter=True,
edgecolor=sns.color_palette("hls", 4),
facecolors="none", split=False, alpha=0.7)
But the color palettes for men and women seem to be different. How do I use the same color palette for both categories?
I am using seaborn 0.6.dev
source to share
The edgecolor parameter is passed directly to plt.scatter
. You are currently giving him a list of 4 colors. I'm not entirely sure what I would expect this to happen in this case (and I'm not entirely sure why you ended up with what you see here), but I would not expect it to "work".
The ideal way to do this job is to have a "hollow circle" glyph marker that colors the edges based on an attribute color
(or facecolor
) rather than edges. While it would be nice to have this as an option in matplotlib core, there are some inconsistencies that might make this not work. However, it is possible to hack a custom glyph that does the trick:
import numpy as np
import matplotlib as mpl
import seaborn as sns
sns.set_style("whitegrid")
df = sns.load_dataset("tips")
pnts = np.linspace(0, np.pi * 2, 24)
circ = np.c_[np.sin(pts) / 2, -np.cos(pts) / 2]
vert = np.r_[circ, circ[::-1] * .7]
open_circle = mpl.path.Path(vert)
sns.stripplot(x="sex", y="tip", hue="day", data=df,
jitter=True, split=False,
palette="hls", marker=open_circle, linewidth=0)
FWIW I should also mention that it is important to be careful when using this approach because colors become much more difficult to distinguish. The palette hls
exacerbates the problem as the bright greens and blues end up being very similar. I can imagine situations where this would work nicely, though for example a hue variable with two levels represented by gray and a bright color where you want to highlight the latter.
source to share