1

I am new to python, I have came across an issue.

To visualize a vector field i am reading x,y,u,v cordinates and it's displacements. Using matplotlib quiver. Now the colouring i want to be based on the length of arrow but it's random now and doesn't make much sense. I went through some stakckoverflow posts and this is what i have added so far.

color_array = np.sqrt(((x[skip]-n)/2)**2 + ((y[skip]-n)/2)**2)

python code

import numpy as np
import matplotlib.pyplot as plt

x,y,z,u,v,w = np.loadtxt(
    'file.txt', 
    unpack=True
    )

n = -2
color_arr = np.sqrt(((x-n)/2)**2 + ((y-n)/2)**2)

plt.quiver(x,y,u,v,
            color_arr,
            scale=5)

plt.show()

enter image description here

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
  • I was able to color arrow based on length using magnitude. This helped https://stackoverflow.com/questions/37706467/color-mapping-a-3d-quiver-function-using-matplotlib – Amir Dora. May 04 '20 at 14:54

0 Answers0