Python 如何学习seaborn的例子
每个官方seaborn演示/示例都以sns.load_数据集开始。我想知道我在哪里可以得到这些seaborn数据集,这样我就可以遵循这些示例了 我试着自己用诸如在哪里找到官方seaborn数据集等短语找到它们,但没有找到 更新: 那么,我如何使用它们呢?我在跟踪,也就是说,我没有任何图表 不过,我的海生熊猫和熊猫都工作得很好。它们来自我的Anaconda安装,都是最新版本。我正在使用的matplotlib版本Python 如何学习seaborn的例子,python,dataset,seaborn,Python,Dataset,Seaborn,每个官方seaborn演示/示例都以sns.load_数据集开始。我想知道我在哪里可以得到这些seaborn数据集,这样我就可以遵循这些示例了 我试着自己用诸如在哪里找到官方seaborn数据集等短语找到它们,但没有找到 更新: 那么,我如何使用它们呢?我在跟踪,也就是说,我没有任何图表 不过,我的海生熊猫和熊猫都工作得很好。它们来自我的Anaconda安装,都是最新版本。我正在使用的matplotlib版本 @gabra,我在提问之前从互联网上找到了这些csv文件,因为我认为它们只是csv文件
@gabra,我在提问之前从互联网上找到了这些csv文件,因为我认为它们只是csv文件,不能直接用于sns.load_datasetxxx,对吗?这些数据集位于另一个名为的存储库中 在此回购协议中,每个数据集都存储为.csv文件 使现代化 试试这个:
import seaborn as sns
%matplotlib inline # To show embedded plots in the notebook
tips = sns.load_dataset("tips")
fig, ax = plt.subplots()
ax = sns.boxplot(tips["total_bill"])
seaborn包应该包括示例教程中引用的示例数据集或检索数据集的方法
# Load the example planets dataset
planets = sns.load_dataset("planets")
当我在中查找行星数据集时,我没有看到数据集。稍微研究一下函数load_数据集,就会发现示例数据集来自在线,需要pandas包依赖性
def load_dataset(name, cache=True, data_home=None, **kws):
"""Load a dataset from the online repository (requires internet).
Parameters
----------
name : str
Name of the dataset (`name`.csv on
https://github.com/mwaskom/seaborn-data). You can obtain list of
available datasets using :func:`get_dataset_names`
cache : boolean, optional
If True, then cache data locally and use the cache on subsequent calls
data_home : string, optional
The directory in which to cache data. By default, uses ~/seaborn_data/
kws : dict, optional
Passed to pandas.read_csv
"""
path = "https://github.com/mwaskom/seaborn-data/raw/master/{0}.csv"
full_path = path.format(name)
if cache:
cache_path = os.path.join(get_data_home(data_home),
os.path.basename(full_path))
if not os.path.exists(cache_path):
urlretrieve(full_path, cache_path)
full_path = cache_path
df = pd.read_csv(full_path, **kws)
if df.iloc[-1].isnull().all():
df = df.iloc[:-1]
if not pandas_has_categoricals:
return df
# Set some columns as a categorical type with ordered levels
if name == "tips":
df["day"] = pd.Categorical(df["day"], ["Thur", "Fri", "Sat", "Sun"])
df["sex"] = pd.Categorical(df["sex"], ["Male", "Female"])
df["time"] = pd.Categorical(df["time"], ["Lunch", "Dinner"])
df["smoker"] = pd.Categorical(df["smoker"], ["Yes", "No"])
if name == "flights":
df["month"] = pd.Categorical(df["month"], df.month.unique())
if name == "exercise":
df["time"] = pd.Categorical(df["time"], ["1 min", "15 min", "30 min"])
df["kind"] = pd.Categorical(df["kind"], ["rest", "walking", "running"])
df["diet"] = pd.Categorical(df["diet"], ["no fat", "low fat"])
if name == "titanic":
df["class"] = pd.Categorical(df["class"], ["First", "Second", "Third"])
df["deck"] = pd.Categorical(df["deck"], list("ABCDEFG"))
return df
数据集与seaborn一起安装。您想知道它们在您的计算机中的位置吗?您使用的matplotlib版本似乎太新,与seaborn版本不兼容。我会考虑使用旧版本的matplotlib。具体来说,可以尝试matplotlib 1.3.1,因为它是在2013年10月发布的,seaborn软件包是在2年前开发的。或者,在过去5个月中,seaborn软件包有很多承诺,这可能是对2015年2月发布的matplotlib 1.4.3的回应。我想两种都试试。你的matplotlib和seaborn版本是什么?嘿,请不要用编辑来改变问题。如果您需要答案中的更多细节,请对具体答案进行评论。如果您有新问题,请使用按钮提出新问题,并链接到此问题以供参考。您使用的matplotlib版本似乎太新,与seaborn版本不兼容。我会考虑使用旧版本的matplotlib.Hmm?我更新的问题应该表明我仍然很困惑和迷茫。请运行print matplotlib.\uuuu version\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。您的问题已从该数据的位置更改为matplotlib的哪个版本与seaborn兼容。我们已经回答了最初的问题,但没有因此获得声誉积分,因为您已经扩展到另一个更耗时的问题。老兄,我说我的matplotlib版本与seaborn兼容,我说我不能使用那些.csv文件。@DanLowe,感谢您的反馈。我更新了它,我希望它更好。