Plotting direction field in python
<p>I want to plot direction field for a simple equation:  </p>

<pre><code>y'  = 3 â 2y
</code></pre>

<p>I have found similar Matlab problem <a href="http://www.math.tamu.edu/~efendiev/math442_spring04/matlabode.pdf" rel="nofollow">here</a> (1.3). But I do not know how to rewrite it to python. My last try is:  </p>

<pre><code>from matplotlib.pyplot import cm
import matplotlib.pyplot as plt
import numpy as np

nx, ny = .3, .3
x = np.arange(-3, 3, nx)
y = np.arange(-2, 2, ny)
X, Y = np.meshgrid(x, y)

dy = X + np.sin(Y)
dx = np.ones((10,10))

plot2 = plt.figure()
plt.quiver(X, Y, dx, dy, 
           color='Teal', 
           headlength=7)

plt.title('Quiver Plot, Single Colour')
plt.show(plot2)
</code></pre>

<p>But I'm getting error:</p>

<pre><code>builtins.ValueError: operands could not be broadcast together with shapes (100,) (280,) 
</code></pre>

<p>I though it will be very simple, but after few hours of searching how to plot a simple direction field, I am quite depressed.</p>

<p><code>dx</code> and <code>dy</code> must be of the same shape as <code>X</code> and <code>Y</code>.</p>

<p>Currently, you have a shape of <code>(14, 20)</code> for <code>X</code>, <code>Y</code> and <code>dy</code>, but <code>(10,10)</code> for <code>dx</code>. </p>

<p>If you change the line defining <code>dx</code> to:</p>

<pre><code>dx = np.ones(dy.shape)
</code></pre>

<p>Everything works fine:</p>

<p><a href="http://i.stack.imgur.com/uYKqY.png" rel="nofollow"><img src="http://i.stack.imgur.com/uYKqY.png" alt="enter image description here"></a></p>

python matlab numpy matplotlib scipy