当试图可视化 numpy.meshgrid() 生成的 "regular" 网格点时,我看到了白色垂直线。为什么会这样?

When trying to visualise "regular" grid points generated by numpy.meshgrid() I am seeing white vertical lines. Why is that the case?

当网格均匀时,我相信人们一定看不到数据点中我认为表示"gap"的垂直线。 以下代码重复了我的问题。The plot is shown here.

import numpy as np
x = np.arange(0,100,1)
y = np.arange(0,100,1)
xmesh,ymesh = np.meshgrid(x,y)
plt.scatter(xmesh,ymesh,s=0.5)
# or plt.plot(xmesh,ymesh,'k.',ms=1)

您看到的是 Moiré pattern 的结果,这是由于您的点与屏幕像素网格之间的空间频率不同。

要解决此问题,请增加 figure/Axes 的大小,以便有足够的像素显示数据中的所有点。

例如,查看这两个图之间的区别:

fig = plt.figure(figsize=(3,3))
plt.scatter(xmesh,ymesh,s=0.5)

fig = plt.figure(figsize=(6,6))
plt.scatter(xmesh,ymesh,s=0.5)