在matplotlib中,我试图为我的数学作业绘制带有阴影的图形,但不断出现此错误。我对python和编码非常陌生(使用了两天),知道这个错误是由于数组拉伸或其他原因造成的。 这是错误和代码:
ValueError:操作数无法与形状(50,)(894,)一起广播
ax1第47行出错。在(y2,d1)之间填充
import numpy as np
import matplotlib.pyplot as plt
import math
#Needs a fig if you want to shade
fig, (ax1) = plt.subplots()
#Graph limits
plt.xlim(-50, 550)
plt.ylim(2800,4300)
#Cost 1 - Function 1, variable t
t = np.arange(1000)
t1 = 28 * t + 78652 / t
plt.plot(t1)
#Cost 2a <106 - Function 2, variable g
g = np.arange(0,106)
g1 = 3 * g + 3392
plt.plot(g1)
#Cost 2b >106 - Function 3, variable d
d = np.arange(106,1000)
d1 = 3 * d + 3392
#Cost2b - Shading
line1 = ax1.plot()
ax1.fill_between(d, d1)
#Revenue <200 - Function 4, variable y and y2 (I think)
f = lambda c1,a : (a * c1) / 150
a = 1
c1 = np.linspace(0, 200)
y = f(c1,a)
y2 = 200 * np.log(y) + 4000
ac1 = plt.plot(c1, y2)
#Shading
line1 = ax1.plot()
ax1.fill_between(y2, d1)
#Revenue >200 - Function 4, variable y and y2 (I think)
f = lambda c2,a : (a * c2) / 150
a = 1
c2 = np.linspace(200, 400)
y = f(c2,a)
y2 = 200 * np.log(y) + 4000
ac2 = plt.plot(c2, y2)
#Show the plot on a graph
plt.show()
谢谢你的帮助
您的物品有不同的形状。。只需执行以下操作: `c1=np.linspace(0200894)'
这将指定
y
的长度,类似于d
。相关问题 更多 >
编程相关推荐