I understand that a contour plot shows lines for all points that share a particular value, but when I draw a contour plot in matplotlib
for the square of the sum of x^2 and y^2, the point for (1.237, 1.237) — computes to 1.75 — lies between the contour lines labeled 2.0 and 2.5.
Shouldn’t that point lie between the contour lines for 1.5 and 2.0?
What am I missing / doing wrong here?
import matplotlib.pyplot as plt
zval = 1.75
print(np.sqrt(zval**2/2)) # 1.237
print(np.sqrt(
np.sqrt(zval**2/2)**2 +
np.sqrt(zval**2/2)**2
)) # 1.75
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.75 but point is plotted beyond the 2 line -- why?
ax.scatter(
x=np.sqrt(zval**2/2),
y=np.sqrt(zval**2/2),
color="orange"
)
plt.grid()
plt.show()```[![Resulting plot][2]][2]
[1]: https://i.sstatic.net/ZkdEZ6mS.png
[2]: https://i.sstatic.net/rObSpLkZ.png