image_output_1.png
import matplotlib.pyplot as plt

# create blank figure

fig, ax = plt.subplots()
plt.show()

# resize figure

fig, ax = plt.subplots(figsize=(10,10))
plt.show()

# set axis with xlim and ylim, title, labels

fig,ax = plt.subplots()

ax.set(xlim=[0.5, 4.5], ylim=[-2, 8], 
       title='An Example Axes',
       ylabel='Y-Axis', xlabel='X-Axis')

plt.show()

# create multiple subplots along rows

fig, ax = plt.subplots(nrows=2)

# create multiple subplots along columns

fig, ax = plt.subplots(ncols=2)

# create multiple subplots along rows and columns

fig, ax = plt.subplots(nrows=2,ncols=2)
plt.show()

# create multiple subplots without overlapping

fig, ax = plt.subplots(nrows=2,ncols=2)
plt.tight_layout() # avoid overlapping
plt.show()

# define the index of subplots

fig, axes = plt.subplots(nrows=2, ncols=2)

axes[0,0].set(title='Upper Left [0,0]')
axes[0,1].set(title='Upper Right [0,1]')
axes[1,0].set(title='Lower Left [1,0]')
axes[1,1].set(title='Lower Right [1,1]')

plt.tight_layout()
plt.show()

x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [2, 3, 4, 5, 6, 7, 8, 9]

fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(10, 10))
ax[0, 0].plot(x, y)
ax[0, 0].bar(x, y)
ax[0, 1].scatter(x, y)
ax[1, 0].bar(x, y)
ax[1, 1].barh(x, y)
plt.show()