title: Computing and drawing vector fields
body: <p>I am trying to draw a potential field for a given object using the following formula:</p>
  
  <pre><code>U=-α_goal*e^(-((x-x_goal )^2/a_goal +(y-y_goal^2)/b_goal ) )
  </code></pre>
  
  <p>using the following code</p>
  
  <pre><code>    # Set limits and number of points in grid
      xmax = 10.0
      xmin = -xmax
      NX = 20
      ymax = 10.0
      ymin = -ymax
      NY = 20
      # Make grid and calculate vector components
      x = linspace(xmin, xmax, NX)
      y = linspace(ymin, ymax, NY)
      X, Y = meshgrid(x, y)
      x_obstacle = 0
      y_obstacle = 0
      alpha_obstacle = 1
      a_obstacle = 1
      b_obstacle = 1
      P = -alpha_obstacle * exp(-(X - x_obstacle)**2 / a_obstacle + (Y - y_obstacle)**2 / b_obstacle)
      Ey,Ex = gradient(P)
      print Ey
      print Ex
  
      QP = quiver(X, Y, Ex, Ey)
  
      show()
  </code></pre>
  
  <p>This code calculates a potential field. How can I plot this potential field nicely? Also, given a potential field, what is the best way to convert it to a vector field? (vector field is the minus gradient of the potential field. )</p>
  
  <p>I would appreciate any help.</p>
  
  <p>I have tried using np.gradient() but the result is not what I have expected:</p>
  
  <p><img src="https://i.stack.imgur.com/FqoB8.png" alt="enter image description here"></p>
  
  <p>What I do expect, is something along these lines:
  <img src="https://i.stack.imgur.com/s9weh.png" alt="enter image description here"></p>
  
  <p>EDIT:
  After changing the two lines in the code:</p>
  
  <pre><code>y, x = np.mgrid[500:-100:200j, 1000:-100:200j] 
  p = -1 * np.exp(-((x - 893.6)**2 / 1000 + (y - 417.35)**2 / 1000))
  </code></pre>
  
  <p>I have an incorrect plot: it seems to be inverted left-right (arrows seem to be in correct spot but not the field):<img src="https://i.stack.imgur.com/nT4Oe.png" alt="enter image description here">
  EDIT:
  Fixed by changing to <code>y, x = np.mgrid[500:-100:200j, -100:1000:200j]</code> Any idea why?</p>