Last active
October 19, 2019 21:24
-
-
Save FBosler/021cc9bcdabd27c19d3223042495ef56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def vertical_mean_line(x, **kwargs): | |
plt.axvline(x.mean(), linestyle ="--", | |
color = kwargs.get("color", "r")) | |
txkw = dict(size=15, color = kwargs.get("color", "r")) | |
label_x_pos_adjustment = 0.08 # this needs customization based on your data | |
label_y_pos_adjustment = 5 # this needs customization based on your data | |
if x.mean() < 6: # this needs customization based on your data | |
tx = "mean: {:.2f}\n(std: {:.2f})".format(x.mean(),x.std()) | |
plt.text(x.mean() + label_x_pos_adjustment, label_y_pos_adjustment, tx, **txkw) | |
else: | |
tx = "mean: {:.2f}\n (std: {:.2f})".format(x.mean(),x.std()) | |
plt.text(x.mean() -1.4, label_y_pos_adjustment, tx, **txkw) | |
_ = data.groupby(['Continent','Year'])['Life Ladder'].mean().reset_index() | |
g = sns.FacetGrid(_, col="Continent", height=4, aspect=0.9, col_wrap=3, margin_titles=True) | |
g.map(sns.kdeplot, "Life Ladder", shade=True, color='royalblue') | |
g.map(vertical_mean_line, "Life Ladder") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment