0% found this document useful (0 votes)
253 views

Python Data Viz Tutorial: Setup Overlaying Plots

This Seaborn cheatsheet covers common functions for creating statistical plots in Python using the Seaborn and Matplotlib libraries. It includes instructions for setting up the necessary packages, importing data, and examples of different plot types like scatter plots, box plots, violin plots, heatmaps, distribution plots, and more. Functions demonstrated include lmplot(), boxplot(), violinplot(), heatmap(), distplot(), countplot(), factorplot(), and jointplot(). Customization options are also covered such as adjusting axis limits, setting themes, and using custom color palettes.

Uploaded by

Rajas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
253 views

Python Data Viz Tutorial: Setup Overlaying Plots

This Seaborn cheatsheet covers common functions for creating statistical plots in Python using the Seaborn and Matplotlib libraries. It includes instructions for setting up the necessary packages, importing data, and examples of different plot types like scatter plots, box plots, violin plots, heatmaps, distribution plots, and more. Functions demonstrated include lmplot(), boxplot(), violinplot(), heatmap(), distplot(), countplot(), factorplot(), and jointplot(). Customization options are also covered such as adjusting axis limits, setting themes, and using custom color palettes.

Uploaded by

Rajas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Seaborn Cheatsheet:

Python Data Viz Tutorial

This Seaborn cheatsheet covers common and useful functions for creating charts and statistical plots in Python.
To see the full gallery of what’s possible, visit the online version at elitedatascience.com.

SETUP Overlaying plots


First, make sure you have the following installed on your computer: plt.figure(figsize=(10,6))
sns.violinplot(x=’Type 1’, y=’Attack’, data=df,
• Python 2.7+ or Python 3
• Pandas inner=None, palette=pkmn_type_colors)
• Matplotlib
sns.swarmplot(x=’Type 1’,
• Seaborn
• Jupyter Notebook (optional, but recommended) y=’Attack’,
data=df,
*note: We strongly recommend installing the Anaconda Distribution, which
comes with all of those packages. color=’k’,
alpha=0.7)

Import libraries and dataset plt.title(‘Attack by Type’)

import pandas as pd
from matplotlib import pyplot as plt Putting it all together
%matplotlib inline stats_df.head()
import seaborn as sns melted_df = pd.melt(stats_df,
df = pd.read_csv(‘Pokemon.csv’, index_col=0) id_vars=[“Name”, “Type 1”, “Type 2”],
*Up-to-date link to the sample dataset can be found here. var_name=”Stat”)
sns.swarmplot(x=’Stat’, y=’value’, data=melted_df, hue=’Type 1’)

Scatterplot plt.figure(figsize=(10,6))

sns.lmplot(x=’Attack’, y=’Defense’, data=df) sns.swarmplot(x=’Stat’, y=’value’, data=melted_df,


hue=’Type 1’, split=True, palette=pkmn_type_colors)
plt.ylim(0, 260)
Adjusting Axes Limits
plt.legend(bbox_to_anchor=(1, 1), loc=2
sns.lmplot(x=’Attack’, y=’Defense’, data=df)
plt.ylim(0, None)
plt.xlim(0, None) Other Plot Types
corr = stats_df.corr()
sns.heatmap(corr)
Preprocess w/ Pandas + Boxplot
stats_df = df.drop([‘Total’, ‘Stage’, ‘Legendary’], axis=1)
sns.distplot(df.Attack)
sns.boxplot(data=stats_df)
sns.countplot(x=’Type 1’, data=df, palette=pkmn_type_colors)
plt.xticks(rotation=-45)
Set Theme + Violinplot
sns.set_style(‘whitegrid’)
g = sns.factorplot(x=’Type 1’, y=’Attack’, data=df,
sns.violinplot(x=’Type 1’, y=’Attack’, data=df)
hue=’Stage’, col=’Stage’, kind=’swarm’)
g.set_xticklabels(rotation=-45)
Set Custom Color Palette
pkmn_type_colors = [‘#78C850’, ‘#F08030’, ‘#6890F0’, ‘#A8B820’,
sns.kdeplot(df.Attack, df.Defense)
‘#A8A878’, ‘#A040A0’, ‘#F8D030’, ‘#E0C068’
sns.jointplot(x=’Attack’, y=’Defense’, data=df
‘#EE99AC’, ‘#C03028’, ‘#F85888’, ‘#B8A038’,
‘#705898’, ‘#98D8D8’, ‘#7038F8’]
sns.violinplot(x=’Type 1’, y=’Attack’, data=df,
palette=pkmn_type_colors)

ELITEDATASCIENCE.COM

You might also like