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

时间:2015-04-17 15:53:55

标签: python matplotlib

我使用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

1 个答案:

答案 0 :(得分:0)

我不完全确定你要做什么,但我会猜测。如果您试图在地块上获得所有网格线交叉点,您可以尝试这样的事情:

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]))