Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # lecture 5, seaborn basics
- import seaborn as sns
- import pandas as pd
- import matplotlib.pyplot as plt
- tips = sns.load_dataset('tips')
- tips['total_cost'] = tips['total_bill'] + tips['tip']
- # reset plotting image
- plt.clf()
- # create the actual plot, bins controls the number
- # of categories (bars) in the plot!
- sns.distplot(tips['total_cost'], bins=30)
- # show the plot to user
- plt.figure()
- # draw second plot to its own image
- plt.clf()
- # if you don't want the kernel density estimation line,
- # you can disable it!
- sns.distplot(tips['tip'], kde=False)
- plt.figure()
- # first clear, then plot, then show figure
- plt.clf()
- sns.countplot(x='smoker', data=tips)
- plt.figure()
- # exact numbers of smokers and non-smokers
- print(tips.groupby('smoker').count())
- plt.clf()
- sns.jointplot(x='total_bill', y='tip', data=tips)
- plt.figure()
- plt.clf()
- sns.jointplot(x='total_bill', y='tip', data=tips, kind="reg")
- plt.figure()
- # NEW FILE
- import seaborn as sns
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- tips = sns.load_dataset('tips')
- flights = sns.load_dataset('flights')
- plt.clf()
- sns.pairplot(tips)
- plt.figure()
- tips_correlations = tips.corr()
- plt.clf()
- sns.pairplot(flights)
- plt.figure()
- flights_correlations = flights.corr()
- plt.clf()
- # by default, barplot shows the average for selected category
- sns.barplot(x='smoker', y='total_bill', data=tips, estimator=np.median)
- plt.figure()
- print(tips['smoker'].value_counts())
- print(tips['day'].value_counts())
- print(tips['time'].value_counts())
- plt.clf()
- sns.boxplot(x='time', y='total_bill', data=tips, hue='day')
- plt.figure()
- plt.clf()
- sns.violinplot(x='day', y='tip', data=tips, hue='smoker', split=True)
- plt.figure()
- # NEW FILE
- import seaborn as sns
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- tips = sns.load_dataset('tips')
- plt.clf()
- sns.stripplot(x='day', y='total_bill',
- data=tips, jitter=True, hue='smoker', split=True)
- plt.figure()
- plt.clf()
- sns.swarmplot(x='day', y='total_bill', data=tips)
- plt.figure()
- plt.clf()
- sns.violinplot(x='day', y='total_bill', data=tips)
- sns.swarmplot(x='day', y='total_bill', data=tips, color='purple')
- plt.figure()
- # NEW FILE
- import seaborn as sns
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- flights = sns.load_dataset('flights')
- tips = sns.load_dataset('tips')
- flights_correlations = flights.corr()
- tips_correlations = tips.corr()
- plt.clf()
- sns.heatmap(tips_correlations, annot=True, cmap="magma")
- plt.figure()
- flights_pivot = flights.pivot_table(index='month', columns='year',
- values='passengers')
- plt.clf()
- sns.heatmap(flights_pivot, linecolor='black',
- linewidths=1)
- plt.figure()
- plt.clf()
- sns.clustermap(flights_pivot, cmap='coolwarm', standard_scale=1)
- plt.figure()
- plt.clf()
- sns.lmplot(x='total_bill', y='tip',
- data=tips, hue='smoker', row="sex",
- markers=['o', 'v'], scatter_kws={'s':100})
- plt.figure()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement