title: Color-mapping a 3D quiver function using matplotlib
body: <p>I have created a lovely 3D displacement vector field in python using Matplotlib and I am happy with the results. However, visually it is not very east to see the magnitude of the displacements only the direction. Is there a way in python that I could use a colour scale for the arrows so that the magnitude of the displacements is clearer/more visible.</p>
  
  <p>This is what I have so far</p>
  
  <pre><code>#%% Import Libraries
  
  from mpl_toolkits.mplot3d import Axes3D
  import matplotlib.pyplot as plt
  import numpy as np
  
  #%% Import tsv file of results
  
  path = 'W:/Scott/Continuous_DIC_Results/A35_L7-8_500x500x1000/'
  name = 'Z=-5,200,-20,20,spm100'
  
  results = np.loadtxt(path+name+'.tsv', dtype=float, comments='#', delimiter=None, converters=None, skiprows=1, usecols=(1,2,3,4,5,6), unpack=False, ndmin=0)
  
  Z,Y,X = results[:,0], results[:,1],results[:,2]
  dz,dy,dx = results[:,3],results[:,4],results[:,5]
  
  
  #%% Plot Displacement Field
  
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  
  ax.quiver(X, Y, Z, dx, dy, dz,              # data
            length=20,                        # arrow length
            color='Tomato'                    # arrow colour
            )
  
  ax.set_title('3D Vector Field')             # title
  ax.view_init(elev=18, azim=30)              # camera elevation and angle
  ax.dist=8                                   # camera distance
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/GVMmI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GVMmI.jpg" alt="My Displacement Vector Field"></a></p>