散点图:
1 import seaborn as sns 2 import pandas as pd 3 from matplotlib import pyplot as plt 4 5 file_path = 'iris.csv' 6 iris = pd.read_csv(file_path) 7 8 # print(iris.info()) 9 print(iris.loc[:,'Name'].unique()) 10 11 12 # hue 关于那一列数据进行区分 fit_reg 回归线 13 sns.lmplot(x='SepalLength',y='PetalLength',data=iris,hue='Name',fit_reg=False) 14 15 plt.show()
直方图:
import seaborn as sns import numpy as np import pandas as pd from matplotlib import pyplot as plt s1 = pd.Series(np.random.randn(1000)) print(s1) # 直方图 # plt.hist(s1) # kde 密度图 hist 直方图 # kde = False 只显示直方图 hist = False 只显示核密度图 rug = True 显示观察条 sns.distplot(s1,kde=False) # sns.kdeplot(s1,shade=True,color='r') plt.show()
柱状图:
1 import seaborn as sns 2 import numpy as np 3 import pandas as pd 4 from matplotlib import pyplot as plt 5 6 # 加载官方的在线数据 7 8 df = sns.load_dataset('flights') 9 10 11 df1 = df.pivot(index='month',columns='year',values='passengers') 12 13 # 柱状图 14 s = df1.sum() 15 16 _x = s.index 17 _y = s.values 18 19 sns.barplot(_x,_y) 20 21 22 plt.show()
热力图:
import seaborn as sns import numpy as np import pandas as pd from matplotlib import pyplot as plt # 加载官方的在线数据 df = sns.load_dataset('flights') df1 = df.pivot(index='month',columns='year',values='passengers') # print(df1.head()) # 热力图 # annot = True 显示value fmt = 'd' 整数 cmap='颜色' # sns.heatmap(df1,annot=True,fmt='d') plt.show()