3

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()
Simon Gibbons
  • 6,969
  • 1
  • 21
  • 34
  • Please, what do you want exactly? a list of (x,y) points in which the grid lines meet? – gboffi Apr 07 '15 at 14:13
  • 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 http://matplotlib.org/examples/pylab_examples/major_minor_demo1.html and/or http://stackoverflow.com/questions/9127434/how-to-create-major-and-minor-gridlines-with-different-linestyles-in-python – gboffi Apr 07 '15 at 14:16

1 Answers1

2

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) )
Simon Gibbons
  • 6,969
  • 1
  • 21
  • 34