绘图和可视化(seaborn)

《Python for Data Analysis》

柱状图

import pandas as pd 
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt 
%matplotlib inline

tips = pd.read_csv('examples/tips.csv')
party_counts = pd.crosstab(tips['day'], tips['size'])
# Not many 1- and 6-person parties
party_counts = party_counts.loc[:, 2:5]

tips['tip_pct'] = tips['tip'] / (tips['total_bill'] - tips['tip'])
sns.barplot(x='tip_pct', y='day', hue='time', data=tips, orient='h')

绘图和可视化(seaborn)_第1张图片

comp1 = np.random.normal(0, 1, size=200)
comp2 = np.random.normal(10, 2, size=200)
values = pd.Series(np.concatenate([comp1, comp2]))
sns.distplot(values, bins=100, color='k')

绘图和可视化(seaborn)_第2张图片

散点图

macro = pd.read_csv('examples/macrodata.csv')
data = macro[['cpi', 'm1', 'tbilrate', 'unemp']]
trans_data = np.log(data).diff().dropna()
trans_data[-5:]

sns.regplot('m1', 'unemp', data=trans_data)
plt.title('Changes in log %s versus log %s' % ('m1', 'unemp'))

绘图和可视化(seaborn)_第3张图片

sns.pairplot(trans_data, diag_kind='kde', plot_kws={'alpha': 0.2})

绘图和可视化(seaborn)_第4张图片

你可能感兴趣的:(可视化,数据分析)