python – 填充两个函数之间的区域
发布时间:2020-12-20 11:42:16 所属栏目:Python 来源:网络整理
导读:import matplotlib.pyplot as pltimport numpy as npdef domain(): x = np.arange(0,10,0.001) f1 = lambda x: (2*x - x**2)**0.5 plt.plot(x,f1(x),label = '$y = sqrt{2x - x^2}$') plt.plot(f1(x),x,label = '$x = sqrt{2y - y^2}$') plt.xlabel('X') p
import matplotlib.pyplot as plt import numpy as np def domain(): x = np.arange(0,10,0.001) f1 = lambda x: (2*x - x**2)**0.5 plt.plot(x,f1(x),label = '$y = sqrt{2x - x^2}$') plt.plot(f1(x),x,label = '$x = sqrt{2y - y^2}$') plt.xlabel('X') plt.ylabel('Y') plt.legend(loc='best') axes = plt.gca() axes.set_xlim([0,5]) axes.set_ylim([0,5]) plt.show() domain() 如何利用 解决方法
@user 5061在代码上是正确的,反函数在那里
import matplotlib.pyplot as plt import numpy as np def domain(): x = np.arange(0,0.001) f1 = lambda x: (2*x - x**2)**0.5 f2 = lambda x: 1 - (1-x*x)**0.5 # other part is f2 = lambda x: 1 + (1-x*x)**0.5 plt.plot(x,label = '$x = sqrt{2y - y^2}$') plt.fill_between(x,f2(x),where=f1(x)>=f2(x),interpolate=True,color='yellow') plt.xlabel('X') plt.ylabel('Y') plt.legend(loc='best') axes = plt.gca() axes.set_xlim([0,5]) plt.show() domain() 不取正分量1(1-x * x)** 0.5,因为它不影响交点. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |