Question #294726

Write a code to plot sine and cosine functions graph using subplot.


Expert's answer

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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS