Python Seaborn #1 – A quick reference

  1. seaborn is a statistical plotting library to interact well with Panda’s DataFrame
  2. It is built directly off the MatplotLib but uses simpler one line syntax
  3. Scatter plots line up a set of two continuous features (Age, Salary, Height, Temp)
  4. pip install seaborn # For installation run this command
  5. Using hue in scatterplot – make your plots from 2D information to 3D information
  6. df = pd.read_csv(“dm_office_sales.csv”)
    plt.figure(figsize=(12,4), dpi=100)
    sns.scatterplot(x=’salary’, y=’sales’, data=df, hue=’level of education’, palette=’Dark2′, style=’level of education’, alpha=0.7)
  7. Aabhar : Jose Portilla (Head of Data Science at Pierian Training) @Udemy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv("dm_office_sales.csv")

sns.scatterplot(x='salary', y='sales', data=df)

# Let us make the figure size better
plt.figure(figsize=(12,4), dpi=100)
sns.scatterplot(x='salary', y='sales', data=df)

# hue - coloring the scatter plots based on a) cateogrical column or b) continuous colum
sns.scatterplot(x='salary', y='sales', data=df, hue='level of education')

# hue - for a continuou value, seaborn takes the gradient automatically - same color faded or smoothens
# Using palette - provide the color map options. Details below:
# below:
sns.scatterplot(x='salary', y='sales', data=df, hue='level of education', palette ='Dark2')

# Size setting of points,
# Higher the sales - bigger the points
sns.scatterplot(x='salary', y='sales', data=df, size='sales' )

# transperency to the points using alpha 0 - Fully transparent, 1 = Default 
sns.scatterplot(x='salary', y='sales', data=df, alpha=0.3)

# Markers - points style - depending upon the categorical column values passed
sns.scatterplot(x='salary', y='sales', data=df, hue='level of education', style='level of education')

df = pd.read_csv("dm_office_sales.csv")
plt.figure(figsize=(12,4), dpi=100)
sns.scatterplot(x='salary', y='sales', data=df, hue='level of education', palette='Dark2', style='level of education', alpha=0.7)