3
votes

I have the coordinates of map of india. x-axis range is 65 to 100 and y-axis range is 0-100. I have generated grid in this range. I want to get the coordinates of the grid plot. how can i get that?

 #!usr/bin/env python
 import matplotlib.pyplot as plt
 import numpy as np
 f = np.loadtxt('New_Coordinate.txt')
 fig = plt.figure()
 ax = fig.gca()
 ax.set_xticks(np.arange(65,100,1))
 ax.set_yticks(np.arange(0,100,1))
 plt.plot(f[:,:1],f[:,1:],'ro')
 plt.grid()
 plt.show()
1
Please, what do you want exactly? a list of (x,y) points in which the grid lines meet? - gboffi
IMVHO one hundred ticks (or even 65) is too much ticks on a single axis... consider that you can have major and minor ticks, the latter possibly w/o labels, and hence avoiding a lot of clutter on your plot. See for examples matplotlib.org/examples/pylab_examples/major_minor_demo1.html and/or stackoverflow.com/questions/9127434/… - gboffi

1 Answers

2
votes

The grid points are created at the locations of the tick marks on both axes.

You can then use itertools.product to get all of the pairs of those points which would be where the grid lines intersect.

import itertools

xticks = ax.get_xticks()
yticks = ax.get_yticks()

gridpoints = list( itertools.product(xticks, yticks) )