Python中的轮廓 [英] Contour in Python
问题描述
Z
的计算方式
from matplotlib.pyplot import contour
contour([X, Y,] Z, [levels], **kwargs)
绘制轮廓?
我知道 Z
的意思是:绘制轮廓的高度值.
但是是通过计算标准偏差还是类似的方法得出的?
But is it drawn by calculating a standard deviation or something like that?
我在每个点之间的平均值?
An average between each point I have?
推荐答案
Z
表示取决于 X
和 Y
轴的数量.如果 X
和 Y
表示一个平面,则可以将 Z
视为一个平面,其点高度取决于 X 给定点的code>和
Y
坐标.轮廓是该表面的顶视图",即投影.一个例子是等高线,它们在经度( X
)和纬度( Y
)变化时报告山脉( Z
)的高度.
在编写时, matplotlib
的 contour
函数绘制了 Z
变量(二维 numpy.ndarray
(原样为 X
和 Y
),无需进一步处理. Z
和 X
和 Y
之间的关系在绘图函数外部定义.
我在下面举一个例子,也许可能有用:
Z
represents a quantity dependent on both X
and Y
axes. If X
and Y
represent a plane, Z
can be thought of as a surface, whose point height depends on the X
and Y
coordinates of that given point. The contour is a "top view" of that surface, a projection. An example are the contour lines which report the heights of the mountains (Z
) as longitude (X
) and latitude (Y
) change.
The contour
function of matplotlib
, as you wrote it, plots the values expressed in the Z
variable (two-dimensional numpy.ndarray
, as X
and Y
) as they are, without further processing. The relationship between Z
and X
and Y
is defined outside the plot function.
I report an example below which, perhaps it may be useful:
# IMPORT
import numpy as np
import matplotlib.pyplot as pl
# INPUT
N = 100
x_min = 0
x_max = 10
y_min = 0
y_max = 10
z_min = 0
z_max = 50
z_step = 1
red = '#de7677'
# DEFINE MESH GRID
x = np.linspace(x_min, x_max, N)
y = np.linspace(y_min, y_max, N)
XX, YY = np.meshgrid(x, y)
# CALCULATE ZZ AS A FUNCTION OF XX AND YY, FOR ESAMPLE, THEIR SUM
ZZ = YY + XX
# PLOT THE CONTOUR
fig, ax = pl.subplots(figsize = (10, 10))
cont = ax.contour(XX,
YY,
ZZ,
levels = np.arange(z_min, z_max + z_step, z_step),
colors = red)
# SET THE CONTOUR LABELS
pl.clabel(cont, fmt = '%d')
# SET THE X AND Y LABEL
ax.set_xlabel('X')
ax.set_ylabel('Y')
pl.show()
这篇关于Python中的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!