Subplots
plt.figure()
plt.subplot(3, 2, 1)
plt.subplot(3, 2, 2)
plt.subplot(3, 2, 6)1. plt.figure()
Creates a new blank figure for plotting.
Think of this as an empty canvas where you'll add multiple subplots.
2. plt.subplot(3, 2, X)
Creates a subplot in a 3-row by 2-column grid.
The third number (
X) indicates the position (1-based index) where the subplot will go.
So:
Subplot Code
Grid Position
subplot(3, 2, 1)
Row 1, Column 1
subplot(3, 2, 2)
Row 1, Column 2
subplot(3, 2, 6)
Row 3, Column 2
plt.figure(figsize=(10, 12))
# The first subplot
plt.subplot(3, 2, 1)
plt.plot(traffic_per_day['Monday']['Hour (Coded)'],
traffic_per_day['Monday']['Slowness in traffic (%)'])
# The rest of the subplots
plt.subplot(3, 2, 2)
plt.subplot(3, 2, 3)
plt.subplot(3, 2, 4)
plt.subplot(3, 2, 5)
plt.subplot(3, 2, 6)
# plt.show() at the end to display the entire grid chart
plt.show()Last updated