import matplotlib.pyplot as plt# Pyplot automatically figures out how to create and manage figures and axes
plt.plot(x, y)- Create a figure and axis
# Single axes
fig, ax = plt.subplots(figsize = (4,4)) # figsize argument is optional
# Multiple axes
fig, (ax1, ax2, ax3) = plt.subplots((1,3), figsize = (4,4)) # 1x3 grid
# 2D axes
fig, axs = plt.subplots(2,2, figsize=(5,5)) # 2x2 grid- Plotting
Plot on the
axobject
ax.plot(x,y)
ax1.plot(x,x**2, label="quadratic")
# for 2D
axs[0,0].hist(x)
axs[0,1].scatter(x, y)- Perform methods on axes
ax.set_xlabel('x_label')
ax.set_ylabel('y_label')
ax.set_title('title')
ax.legend()- For precise layout
fig.tight_layout()- Show plots
plt.show()ax.bist(x)
ax.scatter(x,y)
ax.bar(x,y)
ax.hist2d(x, y)For e.g., two lines on the same graph
- Plot first line
fig, ax1 = plt.subplots()
ax1.plot(x, y)- Make copy of axis
ax2 = ax1.twinx() # share the same x-axiz- Plot second line
ax2.plot(x2, y2)