开始使用免费开始使用

FacetGrids 与 AxesSubplots

在上一节课中,我们了解到 Seaborn 的绘图函数会创建两种不同类型的对象:FacetGrid 对象和 AxesSubplot 对象。为图表添加标题的方法会因对象类型而异。

在提供的代码中,我们使用 relplot() 和 miles per gallon 数据集创建了一个散点图,用于展示汽车重量与马力之间的关系。这个散点图被赋值给变量名 g。请识别它属于哪种对象类型。

我们已经将 Seaborn 导入为 sns,并将 matplotlib.pyplot 导入为 plt

本练习是课程的一部分

Seaborn 数据可视化入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create scatter plot
g = sns.relplot(x="weight", 
                y="horsepower", 
                data=mpg,
                kind="scatter")

# Identify plot type
type_of_g = ____

# Print type
print(type_of_g)
编辑并运行代码