Python,如何在多(4)条曲线之间填充?

Python,如何在多(4)条曲线之间填充?,python,matplotlib,fill,Python,Matplotlib,Fill,我想填充这四个函数描述的曲线之间的区域。不确定在这种情况下如何使用fill\u-between选项。您只能fill\u-between两条曲线,而不是四条曲线。因此,使用您拥有的四条曲线,您可以创建两条曲线,y5和y6,我在下面展示了这两条曲线,然后使用它们在它们之间填充。示例如下所示: 我还使用符号绘制了各个函数,这样就很容易看到刚刚创建的不同的新曲线 fig = plt.figure(num=1) ax=fig.add_subplot(111) def f1(x): return

我想填充这四个函数描述的曲线之间的区域。不确定在这种情况下如何使用
fill\u-between
选项。

您只能
fill\u-between
两条曲线,而不是四条曲线。因此,使用您拥有的四条曲线,您可以创建两条曲线,
y5
y6
,我在下面展示了这两条曲线,然后使用它们在它们之间填充。示例如下所示:

我还使用符号绘制了各个函数,这样就很容易看到刚刚创建的不同的新曲线

fig = plt.figure(num=1)
ax=fig.add_subplot(111)

def f1(x):
    return 1/x
def f2(x):
  return 2/x
def f3(x):
  return np.sqrt(x**2-1)
def f4(x):
  return np.sqrt(x**2-2)
s= np.arange(np.sqrt(2),5,0.05)
t=np.arange(1,5,0.05)
y1=f1(t)
y2=f2(t)
y3=f3(t)
y4=f4(s)
ax.plot(t,y1,'k-',t,y2,'k-',t,y3,'k-',s,y4,'k-')
plt.xlim([1.1,2.1])
plt.ylim([0.5,1.5])
plt.show()
将pylab作为plt导入
将numpy作为np导入
图=plt.图(num=1)
ax=图添加_子批次(111)
def f1(x):返回1/x
def f2(x):返回2/x
def f3(x):返回np.sqrt(x**2-1)
DEFF4(x):返回np.sqrt(x**2-2)
t=np.arange(1,5,1e-4)#如果您想要更好的填充,请使用此选项
t=np.arange(1,5,0.05)
y1=f1(t)
y2=f2(t)
y3=f3(t)
y4=f4(t*(t**2>2)+np.sqrt(2)*(t**2=y6)
plt.xlim([1.1,2.1])
plt.ylim([0.5,1.5])
plt.show()

是否要填充最低和最高功能之间的区域?(每个给定点)
import pylab as plt 
import numpy as np 

fig = plt.figure(num=1)
ax=fig.add_subplot(111)

def f1(x): return 1/x
def f2(x): return 2/x
def f3(x): return np.sqrt(x**2-1)
def f4(x): return np.sqrt(x**2-2)

t=np.arange(1,5,1e-4) # use this if you want a better fill
t=np.arange(1,5,0.05)
y1=f1(t)
y2=f2(t)
y3=f3(t)
y4=f4(t*(t**2>2) + np.sqrt(2)*(t**2<=2) ) # Condition checking

y5 = np.array(map(min, zip(y2, y3)))
y6 = np.array(map(max, zip(y1, y4)))

ax.plot(t,y1, 'red')
ax.plot(t,y2, 'blue')
ax.plot(t,y3, 'green')
ax.plot(t,y4, 'purple')

ax.plot(t, y5, '+', ms=5, mfc='None', mec='black')
ax.plot(t, y6, 's', ms=5, mfc='None', mec='black')

ax.fill_between(t, y5, y6, where=y5>=y6)

plt.xlim([1.1,2.1])
plt.ylim([0.5,1.5])

plt.show()