matplotlib 中的子图
有时您希望在一张图中组合多个子图。
可以使用 plot.subplots() 函数同时创建图形和坐标轴对象。
该函数会返回 figure 和 axes 对象:
import matplotlib.pyplot as plt
# 创建图形和坐标轴
fig, (ax1, ax2) = plt.subplots(number_of_rows, number_of_columns)
现在,您可以使用这些坐标轴对象来生成可视化:
# 使用坐标轴绘制图形
ax1.hist(df['column_1'])
ax2.hist(df['column_2'])
plt.show()
本练习是课程的一部分
面向 R 用户的 Python
交互式实操练习
通过完成这段示例代码来试试这个练习。
import matplotlib.pyplot as plt
# Create a figure with 1 axes
fig, ax = plt.____(1, 1)
# Plot a scatter plot in the axes
____.scatter(tips____, tips____)
plt.show()