Python中的 Matplotlib.axes.Axes.contourf()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.contourf()函数
matplotlib 库的轴模块中的Axes.contourf()函数也用于绘制轮廓。但是contourf绘制填充轮廓,而contourf绘制轮廓线。
Syntax:
Parameters: This method accept the following parameters that are described below:
- X, Y: These parameter are the coordinates of the values in Z.
- Z : This parameter is the height values over which the contour is drawn.
- levels : This parameter is used to determine the numbers and positions of the contour lines / regions.
Returns: This returns the following:
- c :This returns the QuadContourSet.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.contourf()函数:
示例 1:
Axes.contourf(self, *args, data=None, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
from numpy import ma
from matplotlib import ticker, cm
N = 1000
x = np.linspace(-6.0, 6.0, N)
y = np.linspace(-7.0, 7.0, N)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-(X)**2 - (Y)**2)
z = 50 * Z1
z[:5, :5] = -1
z = ma.masked_where(z <= 0, z)
fig, ax = plt.subplots()
cs = ax.contourf(X, Y, z, locator = ticker.LogLocator(),
cmap ="Greens")
cbar = fig.colorbar(cs)
ax.set_title('matplotlib.axes.Axes.contourf() Example')
plt.show()
输出: