关联图 类别图 分布图
回归图 矩阵图 组合图
使用matplotlib实现
import matplotlib.pyplot as plt
%matplotlib inline
x = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
y_bar = [3, 4, 6, 8, 9, 10, 9, 11, 7, 8]
y_line = [2, 3, 5, 7, 8, 9, 8, 10, 6, 7]
plt.bar(x, y_bar)
plt.plot(x, y_line, '-o', color='y')
使用seaborn实现
import seaborn as sns
sns.set() # 申明使用 seaborn默认样式
plt.bar(x, y_bar)
plt.plot(x, y_line, '-o', color='y')
sns.set(context=‘notebook’, style=‘darkgrid’, palette=‘deep’, font=‘sans-serif’, font_scale=1,
color_codes=False, rc=None)
context 控制默认画幅的大小, (‘paper’, ‘notebook’, ‘talk’,‘poster’), poster > talk > notebook > paper
style 控制默认的样式 (darkgrid, whitegrid, dark, white, ticks)
palette 设置预设的调色板 可以传(deep, muted, bright, pastel, dark, colorblind)
font 设置字体 font_scale字体大小
Seaborn常用的绘图api
关联图
•relplot 绘制关系图
•scatterplot 绘制多维度关系散点图
•lineplot 多维度的分析线性图
# relplot 散点图、条形图两种样式
iris = sns.load_dataset('iris')
iris.head()
sns.set()
sns.relplot(x='sepal_length', y='sepal_width', data=iris)
sns.relplot(x='sepal_length', y='sepal_width',hue='species', data=iris)
sns.relplot(x='sepal_length', y='sepal_width',hue='species',style='species', data=iris)
sns.relplot(x='sepal_length', y='sepal_width',hue='species',style='species',kind='line', data=iris)
seaborn 有两类方法 Figure-level 和 Axes-level
Figure-level ‘懒人函数’, 适用于快速应用
Axes-level 和matplotlib结合的更紧密, 可以让两者结合 更灵活的绘图
relplot -> Figure-level
lineplot -> Axes-level
sns.lineplot(x='sepal_length', y='sepal_width',hue='species',style='species', data=iris)
类别图
•catplot -> Figure-level
sns.catplot(x='sepal_length', y='species', data=iris)
sns.catplot(x='sepal_length', y='species',kind='swarm', data=iris)
sns.catplot(x='sepal_length', y='species',kind='box', data=iris) # 箱型图
# 小提琴图
sns.catplot(x='sepal_length', y='species',kind='violin', data=iris)
sns.catplot(x='sepal_length', y='species',kind='boxen', data=iris)
# 绘制点线图
sns.catplot(x='sepal_length', y='species',kind='point', data=iris)
# 条形图
sns.catplot(x='sepal_length', y='species',kind='bar', data=iris)
# 计数条形图
sns.catplot(x='species',kind='count', data=iris)
分布图
•joinplot
•pairplot
•distplot
•kdeplot
sns.distplot(iris['sepal_length']) # 直方图 和 概率密度图
sns.kdeplot(iris['sepal_length']) # 概率密度图
sns.jointplot(x='sepal_length', y='sepal_width', data=iris)
sns.jointplot(x='sepal_length', y='sepal_width', data=iris, kind='kde')
# 回归拟合图
sns.jointplot(x='sepal_length', y='sepal_width', data=iris, kind='reg')
sns.pairplot(iris) # 二元变量分布图
sns.pairplot(iris, hue='species')
# 回归图
sns.lmplot(x='sepal_length', y='sepal_width', hue='species', data=iris)
# 矩阵图
import numpy as np
numpy_temp = np.random.rand(10,10)
numpy_temp
sns.heatmap(numpy_temp)
虽然不完全,但我觉得也挺多的,这要怎么记呀