import numpy as np
import math
import matplotlib.pyplot as plt
import csv
def sig(a, x):
return 1 / (1 + math.exp(-a*x))
def cos(x):
return (math.cos(x)+1)/2
a = []
b = []
c = []
j = np.arange(-math.pi,0, 0.0001)
g = np.arange(-math.pi,0, 0.0002)
k = np.arange(-math.pi,0, 0.0010)
csvfile = "data.csv"
idx, value = "Index","Value"
csvRow = [idx, value]
with open(csvfile, "w", newline='') as fp:
wr = csv.writer(fp, dialect = "excel")
wr.writerow(csvRow)
for i in range(0, len(j), 1):
a.append(cos(j[i]))
##wr.writerow([i,sig(g, j[i])])
for i in range(0, len(g), 1):
b.append(cos(g[i]))
for i in range(0, len(k), 1):
c.append(cos(k[i]))
fp.close()
plt.plot(a)
plt.plot(b)
plt.plot(c)
plt.show()
我想绘制这三个cos函数以比较陡度。为此,我希望所有功能都集中在x轴的中心,如何实现呢? Currently the plot looks like this