Seaborn 常用的 10 种数据分析图表

Seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。其中包括常见的泰坦尼克、鸢尾花等经典数据集。

Seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。其中包括常见的泰坦尼克、鸢尾花等经典数据集。

内置示例数据集

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

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

  1. #查看数据集种类
  2. importseabornassns
  3. sns.get_dataset_names()

seaborn 常用的 10 种数据分析图表

  1. importseabornassns
  2. #导出鸢尾花数据集
  3. data=sns.load_dataset('iris')
  4. data.head()

seaborn 常用的 10 种数据分析图表

1. 散点图

函数sns.scatterplot

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. #小费数据集
  6. tips=sns.load_dataset('tips')
  7. ax=sns.scatterplot(x='total_bill',y='tip',data=tips)
  8. plt.show()

seaborn 常用的 10 种数据分析图表

2. 条形图

函数sns.barplot

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

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. #小费数据集
  6. tips=sns.load_dataset("tips")
  7. ax=sns.barplot(x="day",y="total_bill",data=tips)
  8. plt.show()

seaborn 常用的 10 种数据分析图表

3. 线型图

函数sns.lineplot

绘制折线图和置信区间

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. fmri=sns.load_dataset("fmri")
  6. ax=sns.lineplot(x="timepoint",y="signal",data=fmri)
  7. plt.show()

seaborn 常用的 10 种数据分析图表

4. 箱线图

函数seaborn.boxplot

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. tips=sns.load_dataset("tips")
  6. ax=sns.boxplot(x="day",y="total_bill",data=tips)
  7. plt.show()

seaborn 常用的 10 种数据分析图表

5. 直方图

函数seaborn.distplot

  1. importseabornassns
  2. importnumpyasnp
  3. sns.set()
  4. importmatplotlib.pyplotasplt
  5. %matplotlibinline
  6. np.random.seed(0)
  7. x=np.random.randn(1000)
  8. ax=sns.distplot(x)
  9. plt.show()

seaborn 常用的 10 种数据分析图表

6. 热力图

函数seaborn.heatmap

  1. importnumpyasnp
  2. np.random.seed(0)
  3. importseabornassns
  4. sns.set()
  5. importmatplotlib.pyplotasplt
  6. %matplotlibinline
  7. uniform_data=np.random.rand(10,12)
  8. ax=sns.heatmap(uniform_data)
  9. plt.show()

seaborn 常用的 10 种数据分析图表

7. 散点图矩阵

函数sns.pairplot

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. iris=sns.load_dataset("iris")
  6. ax=sns.pairplot(iris)
  7. plt.show()

seaborn 常用的 10 种数据分析图表

8. 分类散点图

函数seaborn.catplot

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. exercise=sns.load_dataset("exercise")
  6. ax=sns.catplot(x="time",y="pulse",hue="kind",data=exercise)\
  7. plt.show()

seaborn 常用的 10 种数据分析图表

9. 计数条形图

函数seaborn.countplot

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. titanic=sns.load_dataset("titanic")
  6. ax=sns.countplot(x="class",data=titanic)
  7. plt.show()

seaborn 常用的 10 种数据分析图表

10. 回归图

函数 seaborn.lmplot

绘制散点及回归图

  1. importseabornassns
  2. sns.set()
  3. importmatplotlib.pyplotasplt
  4. %matplotlibinline
  5. tips=sns.load_dataset("tips")
  6. ax=sns.lmplot(x="total_bill",y="tip",data=tips)
  7. plt.show()

seaborn 常用的 10 种数据分析图表

©本文为清一色官方代发,观点仅代表作者本人,与清一色无关。清一色对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。本文不作为投资理财建议,请读者仅作参考,并请自行承担全部责任。文中部分文字/图片/视频/音频等来源于网络,如侵犯到著作权人的权利,请与我们联系(微信/QQ:1074760229)。转载请注明出处:清一色财经

(0)
打赏 微信扫码打赏 微信扫码打赏 支付宝扫码打赏 支付宝扫码打赏
清一色的头像清一色管理团队
上一篇 2023年5月6日 07:04
下一篇 2023年5月6日 07:04

相关推荐

发表评论

登录后才能评论

联系我们

在线咨询:1643011589-QQbutton

手机:13798586780

QQ/微信:1074760229

QQ群:551893940

工作时间:工作日9:00-18:00,节假日休息

关注微信