Oct-26-2020, 09:12 AM
Hello all,
I have written some code to produce a contour plot (scalar field) and added a quiver plot (vector gradient) to display the gradient:
Contour:
Quiver:
Would appreciate any help
I have written some code to produce a contour plot (scalar field) and added a quiver plot (vector gradient) to display the gradient:
Contour:
plt.figure() ax1 = plt.axes() w = np.arange(-2, 4.1, 0.1) v = np.arange(-2, 3.1, 0.1) [x, y] = np.meshgrid(w, v) f = np.exp(-x**2-y**2) + 0.5*np.exp(-(x-1.5)**2 -2*y**2) c = np.arange(0.1, 1.0, 0.1) ax1.contour(x, y, f, levels=c) l = np.arange(0.1, 1, 0.2) ax1.contour(x, y, f, levels=l, linewidths=0.5) ax1.set_aspect('equal')
Quiver:
w = np.arange(-2.0, 4.1, 0.5) v = np.arange(-2.0, 3.1, 0.5) [x1, y1] = np.meshgrid(w, v) h1 = np.exp(-x1**2-y1**2) + 0.5*np.exp(-(x1-1.5)**2 -2*y1**2) [gradhv, gradhu] = np.gradient(h1, 0.5) ax1.quiver(x1, y1, gradhu, gradhv, width=0.003, angles='xy', scale_units='xy',\ scale=2)I would like to improve the visual presentation by making the plot larger (a zoomed in view) and making sure that the vector arrows do not cross contour lines (i.e. scaling the arrows so the size of the vector points are still clear but do not cross the contour lines.)
Would appreciate any help