Write a code to plot sine and cosine functions graph using subplot.
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,4*np.pi-1,0.1) # start,stop,step
y = np.sin(x)
z = np.cos(x)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(x, y)
ax1.set_title('Plot of sin from 0 to 4pi')
ax1.set(xlabel='x values from 0 to 4pi')
ax2.plot(x, z)
ax2.set_title('Plot of cos from 0 to 4pi')
ax2.set(xlabel='x values from 0 to 4pi')
plt.show()
Comments
Leave a comment