Python Matplotlib

Matplotlib Subplot

Creating subplots

Matplotlib Subplot

The subplot() function takes three arguments that describes the layout of the figure.

Creating Subplots

import matplotlib.pyplot as plt

# plot 1
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.subplot(1, 2, 1)
plt.plot(x, y)

# plot 2
x = [1, 2, 3, 4, 5]
y = [1, 3, 5, 7, 9]
plt.subplot(1, 2, 2)
plt.plot(x, y)

plt.show()