import numpy as np
import matplotlib.pyplot as plt
print("FUNCTION GRAPHER")
def graph(formula,domain):
x = np.array(domain)
y = eval(formula)
plt.plot(x, y)
plt.show()
formula=input("Function: ")
domainmin=float(input("Min X Value: "))
domainmax=float(input("Max X Value: "))
graph(formula, range(domainmin,domainmax))
これは、グラファーを作成するための私のコードです。ご覧のとおり、ユーザーは関数とドメインを入力できます。単純な y=x 関数でテストしていますが、これがエラーです。入力の設定方法に関係があると思います。
FUNCTION GRAPHER
Function: x
Min X Value: -1
Max X Value: 10
Traceback (most recent call last):
File "/Users/William/Documents/Science/PYTHON/Grapher.py", line 12, in <module>
graph(formula, range(domainmin,domainmax))
TypeError: 'float' object cannot be interpreted as an integer
エラーが発生した後、次のように入力します。
graph('x', range(-1,10))
そして、グラフがポップアップします。Python 3.4 を使用しています。