# 使うもの

• Python2.7(PyCharmインストールしたばっかなので・・・)
• PyCharm community edition（デザインかっこいい！）
• matplotlib（Mac使っていいよと言われると、とりあえずsinカーブ）
• numpy（結構お気に入り）

# 流れ

1. 変化の割合と切片を入力させる
2. xとyのデータを作成
3. matplotlibでグラフを描画

# 製作開始！

とりあえず必要なものをimport

main.py
```import matplotlib.pylab as plt
import numpy as np
```

main.py
```# 省略
import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()
```

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
```

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
ic = 0 if le.split("x")[1] == "" else le.split("x")[1]
```

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
ic = 0 if le.split("x")[1] == "" else le.split("x")[1]

x_rate = 1
y_rate = 1
```

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
ic = 0 if le.split("x")[1] == "" else le.split("x")[1]

x_rate = 1
y_rate = 1

if rate.find("/") > -1:
x_rate = int(rate.split("/")[1])
y_rate = int(rate.split("/")[0])
else:
x_rate = 1
y_rate = 1 if rate == "" else int(rate)
```

あとは変化の量で配列を生成します。

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
ic = 0 if le.split("x")[1] == "" else le.split("x")[1]

x_rate = 1
y_rate = 1

if rate.find("/") > -1:
x_rate = int(rate.split("/")[1])
y_rate = int(rate.split("/")[0])
else:
x_rate = 1
y_rate = 1 if rate == "" else int(rate)

x = np.linspace(-x_rate / 2,x_rate,4)
y = x * y_rate + int(ic)
```

main.py
```import matplotlib.pylab as plt
import numpy as np

print("Liner equation:")
le = raw_input()

rate = le.split("x")[0]
ic = 0 if le.split("x")[1] == "" else le.split("x")[1]

x_rate = 1
y_rate = 1

if rate.find("/") > -1:
x_rate = int(rate.split("/")[1])
y_rate = int(rate.split("/")[0])
else:
x_rate = 1
y_rate = 1 if rate == "" else int(rate)

x = np.linspace(-x_rate / 2,x_rate,4)
y = x * y_rate + int(ic)

plt.plot(x,y,"r-")
plt.show()
```

これで完成です！

あとは実行して一次方程式を入力してあげると描画してくれます。

\$ 4x+5 \$
\$ x+1 \$
\$ -3x-5 \$

まだPythonも初心者なのでアドバイス等お願いします。

Sign up for free and join this conversation.
If you already have a Qiita account log in.