我了解到,等值线图显示了所有共享特定值的点的线. 但当我用matplotlib
绘制x2和y2之和的平方的等值线图时,(1,1)的点(计算为1.41)位于标记为1.5和2.0的等值线之间.
该点不应该位于1.0和1.5的轮廓线之间吗?
同样,(0.707,0.707)的点(计算为1)位于1.5的等值线上. 那个点不应该在1.0轮廓线上吗?
我在这里错过了什么/做错了什么?
import numpy as np
import matplotlib.pyplot as plt
zval = 1
xval = np.sqrt(zval**2/2)
print(xval) # 0.707
yval = xval
print(yval)
print(np.sqrt(xval**2 + yval**2)) # 1
xlist = np.linspace(-3.0, 3.0, 3)
ylist = np.linspace(-3.0, 3.0, 4)
X, Y = np.meshgrid(xlist, ylist)
Z = np.sqrt(X**2 + Y**2)
fig = plt.figure(figsize=(7,6))
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
ax = fig.add_axes([left, bottom, width, height])
cp = ax.contour(X, Y, Z)
ax.clabel(cp, inline=True,
fontsize=10)
ax.set_title('Contour Plot')
ax.set_xlabel('x (cm)')
ax.set_ylabel('y (cm)')
# Z value is 1 but point is plotted beyond the 1.5 line -- why?
ax.scatter(
x=xval,
y=yval,
color="orange"
)
ax.scatter(1,1, color="red")
print(np.sqrt(1**2 + 1**2))
plt.grid()
plt.show()