Skip to content

Instantly share code, notes, and snippets.

@ishidur
Last active August 23, 2018 08:48
Show Gist options
  • Save ishidur/1beb1a431099c0e2e3c24a2d43f02ae6 to your computer and use it in GitHub Desktop.
Save ishidur/1beb1a431099c0e2e3c24a2d43f02ae6 to your computer and use it in GitHub Desktop.
Pythonによる関数の描画 #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 f1(x):
if(x < 40):
return 1.0
else:
return 0.0
def f2(x):
if(x > 40):
return 1.0
else:
return 0.0
if __name__ == '__main__':
x = np.arange(20, 80, 0.1)
y1 = [f1(a) for a in x]
y2 = [f2(a) for a in x]
fig = plt.subplots(num=None, figsize=(10, 8), dpi=120,
facecolor='w', edgecolor='k')
# plt.style.use('dark_background')
plt.plot(x, y1, lw=3, label='goal-1')
plt.plot(x, y2, lw=3, label='goal-2')
# plt.title("sigmoid", fontsize=18)
plt.xlabel('Input', fontsize=20)
plt.ylabel('Output', fontsize=20)
plt.tick_params(labelsize=18)
plt.legend(loc='best', fancybox=True, fontsize=18, framealpha=1)
plt.xlim(20,80)
plt.grid()
plt.savefig('learning1-ideal-output.pdf',
bbox_inches='tight', transparent=False)
plt.savefig('learning1-ideal-output.png',
bbox_inches='tight', transparent=False)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment