使用Matplotlib绘图

我在运行以下代码时收到错误:


import matplotlib.pyplot as plt

import numpy as np


m = 5E5

q = .03

p = .38

e = math.e


x = np.array (range(5))

#factor = e ** ( - x ( p + q ) )

#top = (1 - e ** ( - x ( p + q ) ))

#bottom = (1 + (q / p) ( e ** ( - x ( p + q ) ) ))

y = m * ( (1 - e ** ( - x * ( p + q ) )) / ((1 + (q / p) ( e ** ( - x * ( p + q ) ) ))) )


plt.plot(x,y,label='y = x**2')


plt.title("Testing")

plt.xlabel("x axis")

plt.ylabel("y axis")

plt.grid(alpha = .4,linestyle='--')

plt.plot(x,y,label='y=x**2')

plt.legend()


plt.show()

我不明白错误TypeError:当我运行代码时,“float”对象不可调用。我尝试修改表达式等,但无济于事。任何帮助都会很棒。


呼啦一阵风
浏览 90回答 1
1回答

智慧大石

(q / p) ( e ** ( - x * ( p + q ) ) )您缺少一个运算符(q / p) & ( e ** ( - x * ( p + q ) ) )尝试:y = m * ( (1 - e ** ( - x * ( p + q ) )) / ((1 + (q / p) * ( e ** ( - x * ( p + q ) ) ))) )
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python