Python Forum
quiver plot scaling help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: quiver plot scaling help (/thread-30564.html)



quiver plot scaling help - StillAnotherDave - Oct-26-2020

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:
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


RE: quiver plot scaling help - StillAnotherDave - Oct-26-2020

By simply adjusting the "scale=2" to "scale=4" or higher will make the vector arrows smaller but then you loose detail in terms of the field. So first I want to make the original contour plot bigger so that the arrows can still be kept noticeably different in size.