在python中获取特定绘图的网格点

2024-10-02 16:28:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我用matplotlib绘制了一张地图。我想要地图内所有网格点的坐标,而忽略地图之外的所有网格点。有什么方法可以直接用在这上面吗?Intertools提供了所有的网格点,但我只想要地图中的点。在

import matplotlib.pylab as pt
import itertools
pt.set_xticks(np.arange(65,100,.75))
pt.set_yticks(np.arange(0,100,.75))
gridpoints = list( itertools.product(xticks, yticks) )
print gridpoints

Tags: 方法importpt网格matplotlibnp地图绘制
1条回答
网友
1楼 · 发布于 2024-10-02 16:28:49

我不太清楚你想干什么,但我敢猜一猜。如果要在绘图上获取所有栅格线交点,可以尝试以下操作:

def getGridPoints(ax):
    xticks = ax.get_xticks()
    yticks = ax.get_yticks()
    xmin, xmax = ax.get_xbound()
    ymin, ymax = ax.get_ybound()

    return list( itertools.product( [x for x in xticks if x>xmin and x<xmax],
                                    [y for y in yticks if y>ymin and y<ymax]))

相关问题 更多 >