title: Change grid interval and specify tick labels in Matplotlib
body: <p>I am trying to plot counts in gridded plots, but I haven't been able to figure out how to go about it.</p>
  <p>I want:</p>
  <ol>
  <li><p>to have dotted grids at an interval of 5;</p>
  </li>
  <li><p>to have major tick labels only every 20;</p>
  </li>
  <li><p>for the ticks to be outside the plot; and</p>
  </li>
  <li><p>to have &quot;counts&quot; inside those grids.</p>
  </li>
  </ol>
  <p>I have checked for potential duplicates, such as <a href="https://stackoverflow.com/questions/12608788/">here</a> and <a href="https://stackoverflow.com/questions/10453770/matplotlib-define-size-of-a-grid-on-a-plot">here</a>, but have not been able to figure it out.</p>
  <p>This is my code:</p>
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.ticker import MultipleLocator, FormatStrFormatter
  
  for key, value in sorted(data.items()):
      x = value[0][2]
      y = value[0][3]
      count = value[0][4]
  
      fig = plt.figure()
      ax = fig.add_subplot(111)
  
      ax.annotate(count, xy = (x, y), size = 5)
      # overwrites and I only get the last data point
  
      plt.close()
      # Without this, I get a &quot;fail to allocate bitmap&quot; error.
  
  plt.suptitle('Number of counts', fontsize = 12)
  ax.set_xlabel('x')
  ax.set_ylabel('y')
  plt.axes().set_aspect('equal')
  
  plt.axis([0, 1000, 0, 1000])
  # This gives an interval of 200.
  
  majorLocator   = MultipleLocator(20)
  majorFormatter = FormatStrFormatter('%d')
  minorLocator   = MultipleLocator(5)
  # I want the minor grid to be 5 and the major grid to be 20.
  plt.grid()
  
  filename = 'C:\Users\Owl\Desktop\Plot.png'
  plt.savefig(filename, dpi = 150)
  plt.close()
  </code></pre>
  <p>This is what I get.</p>
  <p><img src="https://i.stack.imgur.com/XKLi0.png" alt="This is what I get:" /></p>
  <p>I also have a problem with the data points being overwritten.</p>
  <p>Could anybody PLEASE help me with this problem?</p>