Skip to content

Instantly share code, notes, and snippets.

@ishidur
Last active August 23, 2018 08:47
Show Gist options
  • Save ishidur/08a772e3ca2d41eee604d8ed4bf1fc62 to your computer and use it in GitHub Desktop.
Save ishidur/08a772e3ca2d41eee604d8ed4bf1fc62 to your computer and use it in GitHub Desktop.
PythonでSigmoid関数を描画 #code
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'sans-serif' # 使用するフォント
# x軸の目盛線が内向き('in')か外向き('out')か双方向か('inout')
plt.rcParams['xtick.direction'] = 'in'
# y軸の目盛線が内向き('in')か外向き('out')か双方向か('inout')
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['xtick.major.width'] = 1.0 # x軸主目盛り線の線幅
plt.rcParams['ytick.major.width'] = 1.0 # y軸主目盛り線の線幅
plt.rcParams['font.size'] = 8 # フォントの大きさ
plt.rcParams['axes.linewidth'] = 1.0 # 軸の線幅edge linewidth。囲みの太さ
def step(x):
if x < 0:
return 0
else:
return 1
def sigmoid(x):
return 1 / (1 + np.exp(-x))
if __name__ == '__main__':
x = np.arange(-10, 10, 0.1)
y = [step(a) for a in x]
# y = sigmoid(x)
fig = plt.figure(figsize=[10, 8])
plt.plot(x, y, color='black', linewidth=3.0)
plt.xlabel('x', fontsize=20)
plt.ylabel('f(x)', fontsize=20)
plt.tick_params(labelsize=18)
plt.grid(which='major', color='black', linestyle='-')
# plt.show()
plt.savefig('step.pdf', bbox_inches='tight', transparent=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment