导入seaborn的数据集方法load_datasets的问题

sns.load_dataset使用报错解决URLError: <urlopen error [Errno 11004] getaddrinfo failed>(windows))

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()

报错了。。。

导入seaborn的数据集方法load_datasets的问题_第1张图片

这个原因是load_dataset()会先从本地的seaborn_data去监测,

我们通过这行代码看看seaborn_data的路径

sns.utils.get_data_home()

然后进入这个文件夹,发现什么数据都没有,如下图:

导入seaborn的数据集方法load_datasets的问题_第2张图片

在源码里面。官方提供了github数据集https://github.com/mwaskom/seaborn-data如下图:

导入seaborn的数据集方法load_datasets的问题_第3张图片

把数据部分下载下来,解压

解压后粘贴到seaborn_data的路径下

导入seaborn的数据集方法load_datasets的问题_第4张图片

再次执行刚才的代码

导入seaborn的数据集方法load_datasets的问题_第5张图片

可以加载到数据了

你可能感兴趣的:(Python,错误日志,python,seaborn)