matplotlib.axes.axes.fill_betweenx - 填充两条垂直曲线之间的区域

matplotlib.axes.axes.fill_betweenx

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

语法:

Axes.fill_betweenx(y, x1, x2=0, where=None, step=None, interpolate=False, *, data=None, **kwargs)

参数:该方法接受如下参数说明:

  • y:该参数包含用于定义曲线的数据点的y坐标。
  • x1:该参数包含用于定义第一条曲线的数据点的x坐标
  • x2:该参数包含用于定义第二条曲线的数据点的x坐标。它是可选的,默认值为0。
  • where:该参数为可选参数。并用于排除一些水平区域的填充。
  • interpolate:可选参数。它是错误条的线宽,默认值为NONE。
  • step:可选参数。用于确定填充是否为阶跃函数。

返回一个包含绘制多边形的PolyCollection。

下面的例子演示了matplotlib.axes.axes.fill_betweenx()函数在matplotlib.axes中的作用:

示例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()

输出:

matplotlib.axes.axes.fill_betweenx

示例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()

输出:

matplotlib.axes.axes.fill_betweenx

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程