title: Plot points over contour - Matplotlib / Python
body: <p>I'm trying to plot some points over a contour using Matplotlib.</p>
  
  <p>I have scalar field from which I want to plot the contour.
  However, my <strong>ndarray</strong> has a dimension 0 x 20, but my real space varies from -4 to 4.</p>
  
  <p>I can plot this contour using this piece of code:</p>
  
  <pre><code>x, y = numpy.mgrid[-4:4:20*1j, -4:4:20*1j]
  
  # Draw the scalar field level curves
  cs = plt.contour(scalar_field, extent=[-4, 4, -4, 4])
  plt.clabel(cs, inline=1, fontsize=10)
  </code></pre>
  
  <p>The problem is 'cause I have to plot some points over this plot, and this points are obtained using the <strong>ndarray</strong>, i.e., I get points varying as this array dimension.</p>
  
  <p>I tried to plot these points using this code:</p>
  
  <pre><code>def plot_singularities(x_dim, y_dim, steps, scalar_field, min_points, max_points, file_path):
      """
      :param x_dim : the x dimension of the scalar field
      :param y_dim : the y dimension of the scalar field
      :param steps : the discretization of the scalar field
      :param file_path : the path to save the data
      :param scalar_field : the scalar_field to be plot
      :param min_points : a set (x, y) of min points of the scalar field
      :param max_points : a set (x, y) of max points of the scalar field
      """
      min_points_x = min_points[0]
      min_points_y = min_points[1]
      max_points_x = max_points[0]
      max_points_y = max_points[1]
  
      plt.figure()
  
      x, y = numpy.mgrid[-x_dim:x_dim:steps*1j, -y_dim:y_dim:steps*1j]
  
      # Draw the scalar field level curves
      cs = plt.contour(scalar_field, extent=[-x_dim, x_dim, -y_dim, y_dim])
      plt.clabel(cs, inline=1, fontsize=10)
  
      # Draw the min points
      plt.plot(min_points_x, min_points_y, 'ro')
  
      # Draw the max points
      plt.plot(max_points_x, max_points_y, 'bo')
  
      plt.savefig(file_path + '.png', dpi=100)
      plt.close()
  </code></pre>
  
  <p>But I got this image:</p>
  
  <p><img src="https://i.stack.imgur.com/koyiB.png" alt="enter image description here"></p>
  
  <p>Which is not correct.</p>
  
  <p>If I change this line:</p>
  
  <pre><code>cs = plt.contour(scalar_field, extent=[-x_dim, x_dim, -y_dim, y_dim])
  </code></pre>
  
  <p>For that one:</p>
  
  <pre><code>cs = plt.contour(scalar_field)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/f5GDK.png" alt="enter image description here"></p>
  
  <p>I get the desired behavior, but the extents doesn't show my real data space, but the <strong>ndarray</strong> dimension.</p>
  
  <p>At last, if I don't plot these points (comment the plot() lines), I can the extents that I want:</p>
  
  <p><img src="https://i.stack.imgur.com/7SZg1.png" alt="enter image description here"></p>
  
  <p>But I have to plot the points.
  Both data are in the same space. 
  But the <strong>contour()</strong> function allows me to specify the grid.
  I could found a manner to do this when plotting the points.</p>
  
  <p>How can I properly set the extents?</p>