## 2. 准备工作

``````import seaborn as sns

``````# Brooklyn travels
df_bklyn = df.query(' pickup_borough == "Brooklyn" ')
# Manhattan Travels
df_mhtn = df.query(' pickup_borough == "Manhattan" ')``````

## 3. 绘制

``````# Creating a grid figure with matplotlib
fig, my_grid = plt.subplots(nrows=1, ncols=2, figsize=(18,8))``````

``````# Histograms
# Plot 1
g1 = sns.histplot(data=df_bklyn, x='distance', ax=my_grid[0])
# Title of the Plot 1
g1.set_title('Histogram of the travels beginning in Brooklyn')

# Plot 2
g2 = sns.histplot(data=df_mhtn, x='distance', ax=my_grid[1])
# Title of the Plot 2
g2.set_title('Histogram of the travels beginning in Manhattan');``````

## 4. 扩展

matplotlib的多个子图的绘制方法非常相似，但让我们观察下在对其进行编码时看看有什么不同。 首先来看一个一行三列的例子，如下：

``````# Creating a grid figure with matplotlib SINGLE ROW EXAMPLE
fig, (g1, g2, g3) = plt.subplots(nrows=1, ncols=3, figsize=(18,8))``````

``````# Creating a grid figure with matplotlib MULTIPLE ROWS EXAMPLE
fig, [(g1, g2, g3), (g4, g5, g6)] = plt.subplots(nrows=2, ncols=3, figsize=(18,8))``````

``````# Creating a grid figure with matplotlib
fig, [(g1, g2), (g3, g4)] = plt.subplots(nrows=2, ncols=2, figsize=(18,8))
# Histograms
# Plot 1
g1.hist(data=df_bklyn, x='distance')
# Title of the Plot 1
g1.set_title('Histogram of the travels beginning in Brooklyn')
# Plot 2
g2.hist(data=df_mhtn, x='distance')
# Title of the Plot 2
g2.set_title('Histogram of the travels beginning in Manhattan')
# Plot 3
g3.hist(data=df_queens, x='distance')
# Title of the Plot 3
g3.set_title('Histogram of the travels beginning in Queens')
# Plot 4
g4.hist(data=df_bronx, x='distance')
# Title of the Plot 4
g4.set_title('Histogram of the travels beginning in Bronx');``````