Seaborn简单画图(一) -- 散点图

import pandas as pd
import numpy as np
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# 打开一个花瓣长宽数据文件
f = open('iris.csv')
iris = pd.read_csv(f)
iris.head()


SepalLength SepalWidth  PetalLength PetalWidth  Name
0   5.1 3.5 1.4 0.2 Iris-setosa
1   4.9 3.0 1.4 0.2 Iris-setosa
2   4.7 3.2 1.3 0.2 Iris-setosa
3   4.6 3.1 1.5 0.2 Iris-setosa
4   5.0 3.6 1.4 0.2 Iris-setosa
# 绘制的颜色字典,zip传入俩个列表
iris.Name.unique()
array(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica'], dtype=object)
color_map = dict(zip(iris.Name.unique(), ['blue','green','red']))

使用matplot

for species, group in iris.groupby('Name'):
    plt.scatter(group['PetalLength'], group['SepalLength'],
               color=color_map[species],
               alpha=0.3,edgecolor=None,
               label=species)
plt.legend(frameon=True, title='Name')
plt.xlabel('PetalLength')
plt.ylabel('SepalLength')

这里写图片描述
使用Seaborn

sns.lmplot('PetalLength','SepalLength',iris,hue='Name', fit_reg=False)

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39778570/article/details/81145721