开始使用免费开始使用

添加注释

我们讲过的每种增强方式都可以组合使用。 在下一个练习中,您将为分布图添加注释,绘制显示房租均值和中位数的竖线。

在此示例中,已使用 sns.set_palette() 将调色板更改为 bright

本练习是课程的一部分

Seaborn 数据可视化进阶

查看课程

练习说明

  • 创建图形和坐标轴。
  • 绘制 fmr_1 列的分布。
  • 使用 axvline 为已定义的 medianmean 值添加竖线。

交互式实操练习

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

# Create a figure and axes. Then plot the data
fig, ax = plt.subplots()
sns.histplot(df['fmr_1'], ax=ax)

# Customize the labels and limits
ax.set(____="1 Bedroom Fair Market Rent", xlim=(100,1500), title="US Rent")

# Add vertical lines for the median and mean
ax.axvline(x=____, color='m', label='Median', linestyle='--', linewidth=2)
ax.axvline(x=____, color='b', label='Mean', linestyle='-', linewidth=2)

# Show the legend and plot the data
ax.____()
plt.show()
编辑并运行代码