代码如下:
import matplotlib.pyplot as plt
from numpy import *
plt.figure(figsize = (8,4))
x_values = arange(0.0,math.pi * 4,0.01)
y_values = sin(x_values)
plt.plot(x_values, y_values, 'b--', label='$sin(x)$', linewidth=1.0)
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.ylim(-1,1)
plt.title('Simple plot')
plt.legend()
plt.grid(True)
plt.savefig("sin.png")
plt.show()
结果如下: