📜  Python中的 Matplotlib.pyplot.fill_between()

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

Python中的 Matplotlib.pyplot.fill_between()

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

matplotlib.pyplot.fill_between()

matplotlib.pyplot.fill_between()用于填充两条水平曲线之间的区域。两点 (x, y1) 和 (x, y2) 定义曲线。这将创建一个或多个描述填充区域的多边形。 '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:

import matplotlib.pyplot as plt
import numpy as np
  
x = np.arange(0,10,0.1)
  
# plotting the lines
a1 = 4 - 2*x
a2 = 3 - 0.5*x
a3 = 1 -x
  
# The upper edge of
# polygon
a4 = np.minimum(a1, a2)
  
# Setting the y-limit
plt.ylim(0, 5)
  
# Plot the lines
plt.plot(x, a1,
        x, a2,
        x, a3)
  
# Filling between line a3 
# and line a4
plt.fill_between(x, a3, a4, color='green',
                 alpha=0.5)
plt.show()

输出:

python-matplotlib-find-between-1

示例 2:

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

输出:

python-matplotlib-fill-between2-