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

在python中获取特定绘图的网格点,python,matplotlib,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(x

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

我不完全确定你想做什么,但我可以大胆猜测一下。如果要获取绘图上的所有轴网线交点,可以尝试以下操作:

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]))
def getGridPoints(ax):
xticks=ax.getxticks()
yticks=ax.get\u yticks()
xmin,xmax=ax.getxbound()
ymin,ymax=ax.get_ybound()

返回列表(itertools.product([x代表x,如果x>xmin,xymin和yIt不清楚“map”是什么意思),因为你的代码没有打印任何东西。我这里有我正在打印的印度地图的坐标。很抱歉没有指定坐标。这些坐标是从文件中读取的,然后打印出来的。你只需要说
pt.set_xlim(max(xvariable),min(xvariable))
y轴也是如此,你的意思是希望所有网格点都位于由另一组点定义的不规则形状内吗?第二组点总是在网格线上,还是不规则?另外:一般来说,这个问题很难——当多边形可能不是凸的,或者不是简单的凸的时候,如何在多边形中找到一个点连接。Google和其他地图工具标签中有很多问题。ax在这里是什么?我取了ax=plt.figure().gca()。是否正确?ax是一个“matplotlib.axes”对象()。我通常使用习惯用法
fig,ax=plt.subplot()
,但
gca()
也可以。