import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-5,5,50)
c1 = 0
c2 = 0.5
c3 = 1
c4 = 100
y1 = x*(1/(1+np.exp(-c1*x)))
y2 = x*(1/(1+np.exp(-c2*x)))
y3 = x*(1/(1+np.exp(-c3*x)))
y4 = x*(1/(1+np.exp(-c4*x)))
plt.figure()
#plt.plot(x,y1,'-',c='r')
#plt.plot(x,y2,'--',c='g')
#plt.plot(x,y3,':',c='b')
#plt.plot(x,y4,'*',c='k')
plt.plot(x,y1,'-',c='r',label='c1 = 0')
plt.plot(x,y2,'--',c='g',label='c1 = 0.5')
plt.plot(x,y3,':',c='b',label='c1 = 1')
plt.plot(x,y4,'4',c='k',label='c1 = 100')
plt.legend(loc='upper left', frameon=True)
#截取x,y的某一部分
plt.xlim((-4,4))
plt.ylim((-4,4))
#设置x,y的描述标签
plt.xlabel(" x")
plt.ylabel(" y")
#设置x的刻度间隔
new_ticks = np.linspace(-4,4,8)
plt.xticks=(new_ticks)
plt.yticks=(new_ticks)
ax = plt.gca() #获取当前坐标的位置
#去掉坐标图的上和右
ax.spines['right'].set_color('None')
ax.spines['top'].set_color('None')
ax.xaxis.set_ticks_position('bottom') # 设置bottom为x轴
ax.yaxis.set_ticks_position('left') # 设置left为x轴
ax.spines['bottom'].set_position(('data',0))#这个位置的括号要注意
ax.spines['left'].set_position(('data',0))
plt.show()
生成的图片如下图所示: