需求:画一个花瓣(petal)和花萼(sepal)长度的散点图
并且颜色要区分
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
iris = pd.read_csv('iris.csv')
iris.head()
type(iris)
通过matplotlib画散点图
print(iris.Name.unique())
color_map = dict(zip(iris.Name.unique(),['blue','green','red']))
#通过matplotlib画散点图
for species,group in iris.groupby('Name'):
plt.scatter(group['PetalLength'],group['SepalLength'],
color = color_map[species],
alpha=0.3,edgecolors=None,
label = species)
plt.legend(frameon = True,title = 'Name')
plt.xlabel('pentalLength')
plt.ylabel('sepaLength')
print(len(list(iris.groupby('Name'))))
print(list(iris.groupby('Name')))
for species,group in iris.groupby('Name'):
print(species)
print('----')
print(group)
利用seaborn,一行代码搞定
import seaborn as sns
#sns.lmplot('PetalLenth','SepalLength',iris,hue='Name',fit_reg = False)
sns.lmplot('PetalLength','SepalLength',iris,hue='Name',fit_reg = False)
fit_reg = True