<jupyter_start><jupyter_text>Introduction to Seaborn<jupyter_code>import seaborn as sns
datasets = sns.get_dataset_names()
datasets
df = sns.load_dataset('car_crashes')
type(df)
df.head(5)
df.shape
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2, 100)

plt.plot(x, x,    label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')

plt.show()

#sns.set() resets seaborn
sns.set()
x = np.linspace(0, 2, 100)

plt.plot(x, x,    label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')

plt.show()
#sns.set() resets seaborn
sns.set_style('whitegrid')
x = np.linspace(0, 2, 100)

plt.plot(x, x,    label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')
plt.show()
x = np.linspace(0, 2, 100)

plt.plot(x, x,    label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')

sns.despine()
current_pallet = sns.color_palette()
sns.palplot(current_pallet)<jupyter_output><empty_output><jupyter_text>Data Visualization with Seaborn<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('../../resources/datasets/BR_eleitorado_2016_municipio.csv', delimiter=";")
df.head()<jupyter_output><empty_output><jupyter_text>Boxplot<jupyter_code>df_target = df.loc[df['total_eleitores'] < 100000].loc[df['total_eleitores'] > 20000]


plt.figure(figsize=(20,10))
g = sns.boxplot(x="uf", y="total_eleitores",data=df_target)

plt.show()<jupyter_output><empty_output><jupyter_text>Barplot<jupyter_code># Count Plot (a.k.a. Bar Plot)
sns.countplot(x='uf', data=df)
 
# Rotate x-labels
plt.xticks(rotation=-90)
df_target = df.nlargest(5, 'total_eleitores')

plt.figure(figsize=(15,15))
g = sns.catplot(x="nome_municipio", y="total_eleitores", data=df_target, height=5, kind="bar",hue = 'uf')
g.set_xticklabels(rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>Scatterplot + Regression Model<jupyter_code>df = pd.read_csv('../../resources/datasets/Pokemon.csv', index_col=0)
df.head()
sns.lmplot(x='Attack', y='Defense', data=df, fit_reg=False)
sns.lmplot(x='Attack', y='Defense', data=df)
# 3a variável (hue)
sns.lmplot(x='Attack', y='Defense', data=df, hue='Legendary')<jupyter_output><empty_output><jupyter_text>Box plot<jupyter_code>plt.figure(figsize=(10,10))

sns.boxplot(data=df)
stats_df = df.drop(['Total', 'Stage', 'Legendary'], axis=1)
stats_df.head(5)

# New boxplot using stats_df
sns.boxplot(data=stats_df)<jupyter_output><empty_output><jupyter_text>Violin Plot<jupyter_code># Set theme
sns.set_style('whitegrid')
 
sns.violinplot(x='Type 1', y='Attack', data=df.head(30))<jupyter_output><empty_output><jupyter_text>Heatmap<jupyter_code>corr = stats_df.corr()
 
# Heatmap
sns.heatmap(corr)<jupyter_output><empty_output><jupyter_text>Seaborn Tools for Data Exploration<jupyter_code>sns.get_dataset_names()
iris = sns.load_dataset("iris")
sns.pairplot(iris)
sns.pairplot(stats_df)
tips = sns.load_dataset("tips")

tips.head()
sns.lmplot(x="total_bill", y="tip", col="time", hue="smoker",data=tips);<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup