美化图形
由于 plt.subplots() 返回的是 axes 对象,您可以使用 .set_title()、.set_xlabel() 和 .set_ylabel() 方法为图形添加标签。
本练习是课程的一部分
面向 R 用户的 Python
练习说明
- 在 axes 上使用
.set_title()方法为图添加标题:'Histogram'。 - 在 axes 上使用
.set_xlabel()方法为图添加 x 轴标签:'Total Bill'。
交互式实操练习
通过完成这段示例代码来试试这个练习。
import matplotlib.pyplot as plt
import seaborn as sns
# Create a figure with 1 axes
fig, ax = plt.subplots()
# Draw a histplot
ax = sns.histplot(tips['total_bill'], kde = True)
# Label the title and x axis
ax.____(____)
____
plt.show()