Home > Software engineering >  How to apply matplotlib quiver autoscale to two vector fields?
How to apply matplotlib quiver autoscale to two vector fields?

Time:01-05

I am plotting two vector fields on top of each other and I want to use the auto-scale feature to set the arrow size such that the two fields are at the same scale automatically. (Part of different scales

If I use scale of second image ignored

I want to set the auto-scale based on both fields, not just one or the other. Ideas?

CodePudding user response:

You need to pass the same scale argument to both plt.quiver calls.

If you don't provide a scale than a visually pleasing scale is enter image description here

CodePudding user response:

Normalizing the data before plotting it can help getting similar scales on the arrow sizes:

scale = 1
UV_real = np.real(UV) / np.linalg.norm(UV)
UV_imag = np.imag(UV) / np.linalg.norm(UV)
Q1 = plt.quiver(*XY, *UV_real, scale=scale)
Q2 = plt.quiver(*XY, *UV_imag, scale=scale, color='g')

enter image description here

Tested for multiple magnitude ratios between real and imaginary parts.

  •  Tags:  
  • Related