matplotlib.axes.Axes.contourf

contourcontourf分别绘制轮廓线和填充轮廓。除非另有说明,两个版本的函数签名和返回值是相同的。**第三个量Z是等高线高度值,第四个量是等高线密度水平

参考链接:https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.contourf.html?highlight=contourf#matplotlib-axes-axes-contourf

x = np.arange(1, 10)
y = x.reshape(-1, 1)
h = x * y

cs = plt.contourf(h, levels=[10, 30, 50],
    colors=['#808080', '#A0A0A0', '#C0C0C0'], extend='both')
cs.cmap.set_over('red')
cs.cmap.set_under('blue')
cs.changed()

 

contourf([X, Y,] Z, [levels], **kwargs)
主要参数
X, Yarray-like, optional

The coordinates of the values in Z.

X and Y must both be 2D with the same shape as Z (e.g. created via numpy.meshgrid), or they must both be 1-D such that len(X) == N is the number of columns in Z and len(Y) == M is the number of rows in Z.

X and Y must both be ordered monotonically.

If not given, they are assumed to be integer indices, i.e. X = range(N), Y = range(M).

Z(M, N) array-like

The height values over which the contour is drawn.

levelsint or array-like, optional

Determines the number and positions of the contour lines / regions.

If an int n, use MaxNLocator, which tries to automatically choose no more than n+1 "nice" contour levels between vmin and vmax.

If array-like, draw contour lines at the specified levels. The values must be in increasing order.

 

 X,类似Yarray,可选

        Z中数值的坐标。

        X和Y必须都是二维的,形状与Z相同(例如通过numpy.meshgrid创建),或者它们必须都是一维的,这样len(X) == N是Z的列数,len(Y) == M是Z的行数。

        X和Y必须都是单调排序的。

        如果没有给出,则假定它们是整数索引,即X=range(N),Y=range(M)。
    Z(M, N) 类似数组

        绘制轮廓的高度值。
    levelint或array-like,可选

        决定轮廓线/区域的数量和位置。

        如果是int n,使用MaxNLocator,它试图在vmin和vmax之间自动选择不超过n+1个 "好的 "轮廓线水平。

        如果是数组,在指定的级别上绘制等高线。这些值必须是递增的。

其他参数

corner_maskbool,默认:rcParams["contour.corner_mask"] (默认:True)。

    启用/禁用角落屏蔽,只有当Z是一个被屏蔽的数组时才会有效果。如果是假的,任何接触到被屏蔽点的四边形都会被屏蔽掉。如果是True,只有离这些点最近的四边形的三角角总是被遮蔽掉,其他由三个未被遮蔽的点组成的三角角照常被轮廓化。
colors color字符串或颜色序列,可选

    层次的颜色,即轮廓线的线条和轮廓线的区域。

    该序列按升序对各层进行循环。如果该序列短于层数,则会重复。

    作为一个快捷方式,可以用单个颜色字符串来代替单元素列表,即用'红'代替['红']来给所有层次涂上相同的颜色。这个快捷方式只对颜色字符串有效,对其他指定颜色的方式无效。

    默认情况下(值为无),将使用cmap指定的颜色映射。
alphafloat,默认为1

    α混合值,在0(透明)和1(不透明)之间。
cmapstr或Colormap,默认:rcParams["image.cmap"] (默认:'viridis')

    一个Colormap实例或注册的Colormap名称。Colormap将级别值映射为颜色。

    如果同时给了颜色和cmap,就会产生一个错误。
normNormalize,可选

    如果使用了colormap,Normalize实例会将级别值缩放到典型colormap范围[0, 1],以便映射到颜色。如果没有给出,则使用默认的线性缩放。
vmin, vmaxfloat, optional

    如果不是无,这些值中的任何一个或两个都将被提供给Normalize实例,覆盖默认的基于级别的颜色缩放比例。
origin{None, 'upper', 'lower', 'image'}, 默认。无

    通过指定Z[0, 0]的位置来决定Z的方向和准确位置。只有在没有给定X、Y的情况下,这才有意义。

        无。Z[0, 0]位于左下角的X=0, Y=0处。

        '低'。Z[0, 0]在左下角的X=0.5, Y=0.5处。

        '上'。Z[0, 0]位于左上角的X=N+0.5, Y=0.5处。

        'image': 使用rcParams["image.origin"]中的值(默认:'upper')。

extent(x0, x1, y0, y1), optional

    如果origin不是None,那么extent的解释和imshow中一样:它给出了外部的像素边界。在这种情况下,Z[0, 0]的位置是像素的中心,而不是一个角。如果原点是None,那么(x0,y0)就是Z[0,0]的位置,(x1,y1)就是Z[-1,-1]的位置。

    如果在调用轮廓时指定了X和Y,这个参数将被忽略。
locatorticker.Locator子类,可选

    如果没有通过level明确给出等高线的级别,那么locator将用于确定等高线的级别。默认为MaxNLocator。
extend{'neither', 'both', 'min', 'max'}, default: 'neither'.

    确定水平线范围外的数值的轮廓着色。

    如果是'两者都不是',那么超出水平线范围的数值就不着色。如果是'min'、'max'或者'both',则对低于、高于或者低于和高于level范围的数值进行着色。

    低于min(level)和高于max(level)的值会被映射到Colormap的under/over值。请注意,大多数Colormap默认没有专门的颜色,所以over和under值是Colormap的边缘值。你可能想用Colormap.set_under和Colormap.set_over来明确设置这些值。

posted @ 2022-04-11 15:22  小白白中白  阅读(187)  评论(0编辑  收藏  举报