python工具——Seaborn

Seaborn是基于matplotlib的图形可视化python包

提供了一种高度交互式界面,便于用户能够做出各种有吸引力的统计图表

在matplotlib的基础上封装了更高级的API,使得作图更加容易

官网 http://seaborn.pydata.org/

安装

pip install seaborn

eg:

柱形图

import matplotlib.pyplot as plt
import seaborn as sns

x = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
y = [3, 4, 6, 8, 9, 10, 9, 11, 7, 8]
sns.barplot(x,y)
plt.show()

使用seaborn自带的经典数据集

直接使用会出现

urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo failed>

产生原因:

  无法访问外网

解决方法:

  手动下载https://github.com/mwaskom/seaborn-data

  放到 C:\Users\当前用户名\seaborn-data下,没有该文件夹手动创建

 

 使用tips的数据生成条形图

import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips")
tips.head()
sns.barplot(x='day',y='tip',data=tips)
plt.show()

 

posted @ 2021-01-07 08:52  慕尘  阅读(445)  评论(0编辑  收藏  举报