📜  Python中的 matplotlib.axes.Axes.fill_betweenx()

📅  最后修改于: 2022-05-13 01:54:58.701000             🧑  作者: Mango

Python中的 matplotlib.axes.Axes.fill_betweenx()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。

matplotlib.axes.Axes.fill_betweenx()函数

matplotlib 库的 axes 模块中的Axes.fill_betweenx()函数用于填充两条垂直曲线之间的区域。

下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.fill_betweenx()函数:

示例 1:

# Implementation of matplotlib function
       
import numpy as np
import matplotlib.pyplot as plt
   
y = np.arange(-5, 5, 0.01)
x1 = -y * 2 + y + 10
x2 = 2 * y + y
   
fig, ax = plt.subplots()
ax.plot(y, x1, y, x2, color ='black')
ax.fill_betweenx(y, x1, x2, where = x2 >x1, 
                 facecolor ='green', alpha = 0.8)
  
ax.fill_betweenx(y, x1, x2, where = x2 <= x1,
                 facecolor ='black', alpha = 0.8)
   
ax.set_title('matplotlib.axes.Axes.fill_betweenx Example1')
plt.show()

输出:

示例 2:

# Implementation of matplotlib function
      
import numpy as np
import matplotlib.pyplot as plt
  
y = np.arange(0.0, 2, 0.01)
x1 = np.sin(2 * np.pi * y)
x2 = 0.8 * np.sin(4 * np.pi * y)
  
fig, [ax1, ax2, ax3, ax4] = plt.subplots(1, 4,
                                         sharey = True,
                                         figsize =(6, 6))
  
ax1.fill_betweenx(y, 0, x1, facecolor ='green')
ax1.set_title('Fill_Betweenx x1 and 0')
  
ax2.fill_betweenx(y, x1, 1, facecolor ='green')
ax2.set_title('Fill_Betweenx x1 and 1')
  
ax3.fill_betweenx(y, x1, x2, facecolor ='green')
ax3.set_title('Fill_Betweenx x1 and y2')
  
ax4.fill_betweenx(y, x1, x2, where = x2 <= x1, 
                  facecolor ='green')
  
ax4.set_title('Fill_Between x1 and x2 with x2<= x1 ' )
plt.show()

输出: