Last active
September 23, 2018 19:11
-
-
Save JonnyCBB/08ac867fafbc728813da2c9b9f612059 to your computer and use it in GitHub Desktop.
Plotting scatter plots with matplotlib and seaborn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import seaborn as sns | |
tips = sns.load_dataset("tips") # Load data | |
# Scatterplot with matplotlib | |
for is_smoker in tips.smoker.unique(): | |
is_smoker_data = tips.query('smoker == @is_smoker') | |
plt.scatter(is_smoker_data['total_bill'], is_smoker_data['tip'], edgecolors='w', label=f'{is_smoker}') | |
plt.legend(title='Smoker') | |
# Scatterplot with Seaborn | |
sns.lmplot(x='total_bill', y='tip', hue='smoker', data=tips, scatter_kws={'edgecolors': 'w'}, fit_reg=False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment