python学习 —— 使用seaborn、matplotlib、pandas、numpy package

优主张 2018-04-16

这里使用了Titanic Machine learning数据集,然后通过Seaborn的函数来拟合和绘制回归线,matplotlib进行可视化

先来一个简单的测试:

import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns

df = pd.read_csv('C:/Users/Administrator/Desktop/Titanic2/test.csv', index_col=0)  # 读取csv表格, index_col=0表示第0列为id
print(df.head(n=5))  # 打印前5行的数据

# sns.lmplot(x='Age', y='Fare', data=df)
sns.jointplot(x='Age', y='Fare', data=df)

# 去掉以下两句代码可发现原点不在最左下角
plt.ylim(0, None)
plt.xlim(0, None)
plt.show()  # 可视化

运行结果:

python学习 —— 使用seaborn、matplotlib、pandas、numpy package

sns.lmplot(x='Age', y='Fare', data=df):

python学习 —— 使用seaborn、matplotlib、pandas、numpy package

sns.jointplot(x='Age', y='Fare', data=df):

python学习 —— 使用seaborn、matplotlib、pandas、numpy package

未完待续。。。

相关推荐