温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

seaborn如何绘制各种图形

发布时间:2020-07-03 15:05:03 来源:亿速云 阅读:181 作者:清晨 栏目:编程语言

这篇文章主要介绍seaborn如何绘制各种图形,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!


内置示例数据集

seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。

其中包括常见的泰坦尼克、鸢尾花等经典数据集。

# 查看数据集种类
import seaborn as sns
sns.get_dataset_names()
import seaborn as sns
# 导出鸢尾花数据集
data = sns.load_dataset('iris')
data.head()

1、散点图

函数sns.scatterplot

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
# 小费数据集
tips = sns.load_dataset('tips')
ax = sns.scatterplot(x='total_bill',y='tip',data=tips)
plt.show()

seaborn如何绘制各种图形

2、条形图

函数sns.barplot

显示数据平均值和置信区间

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
# 小费数据集t
ips = sns.load_dataset("tips")
ax = sns.barplot(x="day", y="total_bill", data=tips)
plt.show()

3、线型图

函数sns.lineplot

绘制折线图和置信区间

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
plt.show()

4、箱线图

函数seaborn.boxplot

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
plt.show()

5、直方图

函数seaborn.distplot

import seaborn as sns
import numpy as np
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed(0)
x = np.random.randn(1000)
ax = sns.distplot(x)
plt.show()

6、热力图

函数seaborn.heatmap

import numpy as np
np.random.seed(0)
import seaborn as sns 
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
plt.show()

7、散点图矩阵

函数sns.pairplot

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
iris = sns.load_dataset("iris")
ax = sns.pairplot(iris)
plt.show()

8、分类散点图

函数seaborn.catplot

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
exercise = sns.load_dataset("exercise")
ax = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)\
plt.show()

9、计数条形图

函数seaborn.countplot

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
titanic = sns.load_dataset("titanic")
ax = sns.countplot(x="class", data=titanic)
plt.show()

10、回归图

函数 seaborn.lmplot

绘制散点及回归图

import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_dataset("tips")
ax = sns.lmplot(x="total_bill", y="tip", data=tips)
plt.show()

以上是seaborn如何绘制各种图形的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI