计算两条曲线之间的面积 [英] Calculation of areas between two curves
问题描述
大家好,
我有一个包含曲线和一条线的代码。我知道如何填充下面和下面的区域,但我需要计算每个区域的面积值。
这里是代码:
导入matplotlib.pyplot作为plt
导入numpy为np
x = np.arange(0.0,2,0.01)
y1 = np.sin(2 * np.pi * x)
y2 = 0 * x
< br $> b $ b
fig,ax = plt.subplots(1,1,sharex = True)
ax.plot(x,y1,x,y2) ,color ='black')
ax.fill_between(x,y1,y2,where = y2> = y1,facecolor ='green',interpolate = True)
ax.fill_between(x,y1,y2,where = y2< = y1,facecolor ='red',interpolate = True)
ax.set_title('填充在哪里')
plt.show()
任何帮助?
我尝试了什么:
i试图在谷歌搜索,但我找不到它!!
Hello everyone,
i have a code contain a curve and a line. i know how to fill the areas below and under the line but i need to calculate the areas values of each one.
here is the code:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2*np.pi*x)
y2 = 0*x
fig, ax = plt.subplots(1, 1, sharex=True)
ax.plot(x, y1, x, y2, color='black')
ax.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True)
ax.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red', interpolate=True)
ax.set_title('fill between where')
plt.show()
any help ?
What I have tried:
i tried searching in Google but i can't find it !!
推荐答案
这是一个数学问题秒。请参阅曲线下的区域 - Google搜索 [ ^ ]。
This is a question of mathematics. See area under a curve - Google Search[^].
这篇关于计算两条曲线之间的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!