1
x_data=np.linspace(-np.pi,np.pi,256,endpoint=True)
y1_data=np.cos(x_data)
plt.plot(x_data,y1_data)
plt.show()
2
import matplotlib.pyplot as plt
import numpy as np
data=np.array([1,2,3,4,5])
plt.plot(data)
plt.show()
3
import matplotlib.pyplot as plt
import numpy as np
plt.title("sin&cos")
x = np.linspace(-np.pi,np.pi,200)
plt.plot(x,np.sin(x),'-g')
plt.plot(x,np.cos(x),':b')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
4
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(-np.pi,np.pi,200)
y1 = np.sin(x)
y2 = np.cos(x)
ax.plot(x,np.sin(x),'-g',label='sin(x)')
ax.plot(x,np.cos(x),'--b',label='cos(x)')
ax.set_xlim(left=-np.pi,right=np.pi,emit=True,auto=False)
ax.set_xticks([-np.pi,-np.pi/2,0,np.pi/2,np.pi],[r'$-\pi$',r'$-\pi/2$',r'$0$',r'$\pi/2$',r'$\pi$'])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title("sin & cos")
ax.grid(True)
ax.legend()
plt.show()