使用 matplotlib 轴对象
Seaborn 使用 matplotlib 作为底层绘图库。
大多数情况下,您可以通过 Seaborn 的 API 来修改可视化;不过有时使用 matplotlib 的函数来进一步定制图形也很有帮助。在这种情况下,最重要的对象是 matplotlib 的 axes。
一旦您获得一个 axes 对象,就可以对图形进行大量自定义。
在这些示例中,已将美国 HUD 数据加载到数据框 df 中,并且相关库都已导入。
本练习是课程的一部分
Seaborn 数据可视化进阶
练习说明
- 使用
plt.subplots()创建一个 figure 和 axes 对象。 - 在该 axes 上绘制列
fmr_3的histplot。 - 将 x 轴的标签设置为更有意义的 "3 Bedroom Fair Market Rent"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a figure and axes
fig, ax = plt.____()
# Plot the distribution of data
sns.histplot(df['fmr_3'], ax=ax)
# Create a more descriptive x axis label
ax.set(____="3 Bedroom Fair Market Rent")
# Show the plot
plt.show()