Created
November 2, 2021 04:38
-
-
Save Thiagobc23/44a0a25a4c76f693ea665767b68c7027 to your computer and use it in GitHub Desktop.
Ridge plot with Seaborn
This file contains 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
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import pandas as pd | |
# DATA | |
url = 'https://gist.githubusercontent.com/Thiagobc23/4ccb4ea1c612d9d68921bf990ce28855/raw/07af955c17d1816aba58dea74d65f60210702a15/film.csv' | |
df = pd.read_csv(url, index_col='ID') | |
# Theme | |
sns.set_theme(style="white", rc={"axes.facecolor": (0, 0, 0, 0), 'axes.linewidth':2}) | |
palette = sns.color_palette("Set2", 12) | |
# create a grid with a row for each 'Language' | |
g = sns.FacetGrid(df, palette=palette, row="Language", hue="Language", aspect=9, height=1.2) | |
# map df - Kernel Density Plot of IMDB Score for each Language | |
g.map_dataframe(sns.kdeplot, x="IMDB Score", fill=True, alpha=1) | |
g.map_dataframe(sns.kdeplot, x="IMDB Score", color='black') | |
# function to draw labels | |
def label(x, color, label): | |
ax = plt.gca() #get current axis | |
ax.text(0, .2, label, color='black', fontsize=13, | |
ha="left", va="center", transform=ax.transAxes) | |
# iterate grid to plot labels | |
g.map(label, "Language") | |
# adjust subplots to create overlap | |
g.fig.subplots_adjust(hspace=-.5) | |
# remove subplot titles | |
g.set_titles("") | |
# remove yticks and set xlabel | |
g.set(yticks=[], xlabel="IMDB Score") | |
# remove left spine | |
g.despine(left=True) | |
# set title | |
plt.suptitle('Netflix Originals - IMDB Scores by Language', y=0.98) | |
plt.savefig('ridgeplot.png') |
Author
Thiagobc23
commented
Nov 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment