Creating Scatterplots with Seaborn

Want to learn more? I recommend these Python books: Python for Data Analysis, Python Data Science Handbook, and Introduction to Machine Learning with Python.

Preliminaries

import pandas as pd
%matplotlib inline
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()

df['x'] = random.sample(range(1, 1000), 5)
df['y'] = random.sample(range(1, 1000), 5)
df['z'] = [1,0,0,1,0]
df['k'] = ['male','male','male','female','female']
df.head()
x y z k
0 859 714 1 male
1 70 321 0 male
2 378 12 0 male
3 737 93 1 female
4 375 956 0 female

Scatterplot

sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot('x', 'y',
           data=df,
           fit_reg=False,
           dropna=True,
           hue="z",  
           scatter_kws={"marker": "D",
                        "s": 100})
plt.title('Histogram of IQ')
plt.xlabel('Time')
plt.ylabel('Deaths')
<matplotlib.text.Text at 0x10b4a0850>

png