我是python和matplotlib库的新手,我试图在绘图中得到函数行下方的区域。我有一个变量a&;b,它在我的绘图中移动一个矩形。我也许可以使用原始数学来解决这个问题,但我想知道是否有一种更简单的方法来实现我正在尝试使用matplotlib实现的功能。在
我的情节是这样的
我想知道这个区域的面积
如果,还有一个简单的方法来给这个区域上色,我也想听听。在
以下是显示此图的代码:plt.clf()
plt.draw()
plt.axis(xmin = 0, xmax = 80, ymin = 0, ymax = 5)
plt.plot(-np.cbrt(np.power(t, 2) - 16 * t + 63) +4)
currentAxis = plt.gca()
line = currentAxis.lines[0]
for x, y in zip(line.get_xdata(), line.get_ydata()):
if x == 0 or y == 0:
if b > a:
currentAxis.add_patch(patches.Rectangle(((a * 80 / 11), y), (b * 80 / 11) - (a * 80 / 11), 5, fill=False))
else:
currentAxis.add_patch(patches.Rectangle((-(b * 80 / 11) + 80, y), -(a * 80 / 11) + (b * 80 / 11), 5, fill=False))
plt.show()
谢谢你的帮助,抱歉没有嵌入图片。在