Skip to content

Instantly share code, notes, and snippets.

View cereniyim's full-sized avatar

Ceren cereniyim

View GitHub Profile
@cereniyim
cereniyim / Hist_25bins.py
Last active October 15, 2019 13:41
Histogram with 25 bins
# set the plot
plt.hist(df.life_expectancy,
range=(df.life_expectancy.min(), df.life_expectancy.max()+1),
bins=25,
alpha=0.5)
# set title, legends and labels and xticks
plt.xlabel("Life Expectancy")
plt.ylabel("Count")
plt.title("Histogram of Life Expectancy between 1952 and 2007 in the World")
@cereniyim
cereniyim / Hist_5bins.py
Last active October 15, 2019 13:40
Histogram with 5 bins
# set the plot
plt.hist(df.life_expectancy,
range=(df.life_expectancy.min(), df.life_expectancy.max()+1),
bins=5,
alpha=0.5)
# set title, legends and labels and xticks
plt.xlabel("Life Expectancy")
plt.ylabel("Count")
plt.title("Histogram of Life Expectancy between 1952 and 2007 in the World")
@cereniyim
cereniyim / KDE_plot.py
Last active October 15, 2019 13:32
KDE Plot
ax = sns.kdeplot(df.life_expectancy, shade=True, color="b")
# set the title and x,y labels
plt.title("KDE Plot of Life Expectancy between 1952 and 2007 in the World")
plt.ylabel("Density")
@cereniyim
cereniyim / Dist_plot.py
Last active October 15, 2019 13:38
Distributionplot
ax = sns.distplot(df.life_expectancy, hist=True, color="b")
# set title and x,y labels
plt.title("Distribution Plot of Life Expectancy between 1952 and 2007 in the World")
plt.ylabel("Density")
@cereniyim
cereniyim / KDE_plot_multiple_cat.py
Last active October 15, 2019 13:38
KDE plot with multiple categories
# create list of continents
continents = df['continent'].value_counts().index.tolist()
# set kde plot for each continent
for c in continents:
subset = df[df['continent'] == c]
sns.kdeplot(subset["life_expectancy"], label=c, linewidth=2)
# set title, x and y labels
plt.title("KDE Plot of Life Expectancy Among Continents Between 1952 and 2007")
@cereniyim
cereniyim / Boxplot.py
Created October 15, 2019 13:45
Boxplot
# set the plot and title
sns.boxplot(x="life_expectancy", data=df, palette="Set3")
plt.title("Boxplot of Life Expectancy between 1952 and 2007 in the World")
@cereniyim
cereniyim / Boxplot_cat.py
Last active October 15, 2019 14:26
Boxplot with Categories
# set the plot with the ordered continents and title
sns.boxplot(x="continent", y="life_expectancy", data=df,
palette="Set3",
order=["Africa", "Asia", "Americas", "Europe", "Oceania"])
plt.title("Boxplot of Life Expectancy Among Continents Between 1952 and 2007")
@cereniyim
cereniyim / Boxenplot.py
Created October 15, 2019 13:51
Boxenplot
# set plot and title
sns.boxenplot(x="life_expectancy", data=df,palette="Set3")
plt.title("Boxenplot of Life Expectancy Among Continents Between 1952 and 2007")
@cereniyim
cereniyim / Boxenplot_cat.py
Last active October 15, 2019 14:28
Boxenplot with categories
# set plot with ordered continents and title
sns.boxenplot(x="continent", y="life_expectancy", data=df,
palette="Set3",
order=["Africa", "Asia", "Americas", "Europe", "Oceania"])
plt.title("Boxenplot of Life Expectancy Among Continents Between 1952 and 2007")
@cereniyim
cereniyim / Violinplot.py
Created October 15, 2019 14:04
Violinplot
# set plot and title
sns.violinplot(x="life_expectancy", data=df, palette="Set3")
plt.title("Violinplot of Life Expectancy between 1952 and 2007 in the World")