赞
踩
- import seaborn as sns
- import matplotlib.pyplot as plt
-
- # 使用Seaborn自带的数据集
- tips = sns.load_dataset('tips')
-
- # 绘制柱状图
- sns.barplot(x='day', y='total_bill', data=tips)
-
- # 添加标题和标签
- plt.title('Bar Plot')
- plt.xlabel('Day')
- plt.ylabel('Total Bill')
-
- # 展示图表
- plt.show()

报错了。。。
这个原因是load_dataset()会先从本地的seaborn_data去监测,
我们通过这行代码看看seaborn_data的路径
sns.utils.get_data_home()
然后进入这个文件夹,发现什么数据都没有,如下图:
在源码里面。官方提供了github数据集https://github.com/mwaskom/seaborn-data如下图:
把数据部分下载下来,解压
解压后粘贴到seaborn_data的路径下
再次执行刚才的代码
可以加载到数据了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。