06 01 Introduction to Seaborn - HannaAA17/Data-Scientist-With-Python-datacamp GitHub Wiki
What is Seaborn?
- Python data visualization library.
- Is useful for explore data and communicate results.
- Work well with
pandas
data structures and is built on top of matplotlib
.
sns.scatterplot(x= ,y= )
,sns.countplot(x=, y=)
can work with lists.
Using pandas with Seaborn
- Seaborn only works with tidy pandas dataframe
Making a count plot with a DataFrame
# Import Matplotlib, Pandas, and Seaborn
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Create a DataFrame from csv file
df = pd.read_csv(csv_filepath)
# Create a count plot with "Spiders" on the x-axis
sns.countplot(x='Spiders',data=df)
# Display the plot
plt.show()
Adding a third variable with hue
hue
allows us to easily make subgroups within Seaborn plots
- A scatter plot with hue
sns.scatterplot(x='total_bill', y='tip', data=tips, hue='smoker')
- setting hue order
sns.scatterplot(x='total_bill', y='tip', data=tips, hue='smoker', hue_order=['yes','No'])
- specifying hue colors
hue_colors = {"Yes": "black", "No": "red"}
sns.scatterplot(x='total_bill',
y='tip',
data=tips,
hue='smoker',
palatte=hue_colors)