📜  Python中的 Matplotlib.pyplot.fill_betweenx()

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

Python中的 Matplotlib.pyplot.fill_betweenx()

Matplotlib 是Python中用于数组二维图的惊人可视化库。 Matplotlib 是一个基于 NumPy 数组构建的多平台数据可视化库,旨在与更广泛的 SciPy 堆栈配合使用。

matplotlib.pyplot.fill_betweenx()

matplotlib.pyplot.fill_betweenx()用于填充两条垂直曲线之间的区域。两个点 (x1, y) 和 (x2, y) 定义曲线。这将创建一个或多个描述填充区域的多边形。 'where' 参数可用于选择性地填充某些区域。默认情况下,边直接连接给定的点。如果填充需要是阶跃函数,则使用“阶跃”参数。

其他参数: **kwargs 包含来自控制多边形属性的 PolyCollection 的关键字;

PropertyDescription
agg_filtera filter function that takes a (m, n, 3) float array and a dpi value that returns a (m, n, 3) array
alphafloat or None
animatedbool
arrayndarray
capstyle{‘butt’, ’round’, ‘projecting’}
clima length 2 sequence of floats; may be overridden in methods that have vmin and vmax kwargs.
cmapcolormap or registered colormap
antialiased or aa or antialiasedsbool or sequence of bools
clip_boxBbox
clip_onbool
clip_path[(Path, Transform)|Patch|None]
colorcolor or sequence of rgba tuples
containscallable
edgecolor or ec or edgecolorscolor or sequence of colors or ‘face’
facecolor or fc or facecolorscolor or sequence of colors
figurefigure
gidstr
hatch{‘/’, ‘\’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’}
in_layoutbool
joinstyle{‘miter’, ’round’, ‘bevel’}
linestyle or ls or linestyles or dashes{‘-‘, ‘–‘, ‘-.’, ‘:’, ”, (offset, on-off-seq), …}
linewidth or linewidths or lwfloat or sequence of floats
normNormalize
offset_position{‘screen’, ‘data’}
offsetsfloat or sequence of floats
path_effectsAbstractPathEffect
pickerNone or bool or float or callable
pickradiusunknown
path_effectsAbstractPathEffect
pickerfloat or callable[[Artist, Event], Tuple[bool, dict]]
pickradiusfloat
rasterizedbool or None
sketch_params(scale: float, length: float, randomness: float) 
 
snapbool or None
transformmatplotlib.transforms.Transform
urlstr
urlsList[str] or None
visiblebool
xdata1D array
zorderfloat

示例 1:

Python3
import matplotlib.pyplot as plt
import numpy as np
 
a = np.linspace(0,2*3.14,50)
b = np.sin(a)
 
plt.fill_betweenx(a, b, 0,
                  where = (a > -0.5) & (a <= 1),
                  color='g')
 
plt.plot(a, b)


Python3
import pylab as plt
import numpy as np
 
N  = np.linspace(0,3,200)
A1 = N**2 + 3
A2 = np.exp(N) + 2
A3 = np.cos(N)
 
plt.plot(N, A1, lw = 3)
plt.plot(N, A2, lw = 3)
plt.plot(N, A3, lw = 3)
 
plt.fill_betweenx(N, A1, A2,
                  color = 'r',
                  alpha = .5)
plt.fill_betweenx(N, A1, A3,
                  color = 'g',
                  alpha = .5)
 
plt.show()


输出:

python-matplotlib-fillbetweenx-1

示例 2:

Python3

import pylab as plt
import numpy as np
 
N  = np.linspace(0,3,200)
A1 = N**2 + 3
A2 = np.exp(N) + 2
A3 = np.cos(N)
 
plt.plot(N, A1, lw = 3)
plt.plot(N, A2, lw = 3)
plt.plot(N, A3, lw = 3)
 
plt.fill_betweenx(N, A1, A2,
                  color = 'r',
                  alpha = .5)
plt.fill_betweenx(N, A1, A3,
                  color = 'g',
                  alpha = .5)
 
plt.show()

输出:

python-matplotlib-fillbetweenx-2