Fork me on GitHub

用matplotlib包画函数图像

画Sinx函数图像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#正弦函数图像
#author:victor

#import module
import numpy as np
import matplotlib.pyplot as plt

#generate number
x=np.arange(0,2*np.pi,0.00001)
y=np.sin(x)

#display the graph
plt.plot(x,y)
plt.show()

sinx

画cosx/x的图像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#画出cosx/x的图像
#author:victor

#import module
import numpy as np
import matplotlib.pyplot as plt

#define function
def f(x):
return np.cos(x*30)/x

#generate number
g=np.frompyfunc(f,1,1)
a=np.arange(0.1,2*np.pi,0.00001)

#use the function
d=g(a)

#set maxsize
d_max=np.max(d)
#set minsize
d_min=np.min(d)

#display the graph
plt.figure(figsize=(52,23.65))
plt.xlim((-0.1,2*np.pi+0.1))
plt.ylim((-5,5))
plt.plot(a,d,'-',c='g',lw=2)
plt.show()

cosx/x