0

I have a collection of particles, each represented by 4 features stored in 4 lists: energy, x_momentum, y_momentum, z_momentum.

Please find here an example with 4 particles:

x_momentum = [0.15216761841647822, 0.0018606956403060416, -0.2581646413098657, -0.06464056152956568]
y_momentum = [-0.006669552300356048, -0.21579226398008983, -0.16226640845867094, 0.029532453059122506]
z_momentum = [0.8616288523834605, 1.5346175299954392, 0.5915564583369708, 0.08989557604945903]
energy = [0.8764152818624683, 1.55052272693799, 0.6673967431272858, 0.12502712734367252]

I would like to plot each particle as an arrow in a 3-d space pointing in the space according its xyz momentum with the following specifications:

  1. each arrow should have a length according to its energy (higher energy longer arrow and vice-versa)
  2. each arrow should have a colour that depends on the direction according to a gradient. e.g. red for the arrows pointing mostly towards the same direction and blue for arrows pointing to more random directions.
  3. if point 1 and 2 not possible, at least the colour should reflect the energy i.e. all the arrows long the same but higher energy means reddish colours lower energy means blueish colour.
  4. lastly, I would like to resize the grid. right now it goes from -0.5 to 0.5 each axis but does not contain all the arrows. Moreover, if I am able to solve point 1. I want the axes to be coherent with the size of the arrows which depend on the energy. Therefore, if for example the highest energy is 3 and subsequently the arrow with that energy is long 3, than the range of the axes should be something like -4 to 4 to contain the arrow.

This is the code I have been able to write (python3).

fig = plt.figure(figsize=(20,16))
ax = fig.gca(projection='3d')

# Make the grid
x, y, z = 0,0,0

# Make the direction data for the arrows
u = x_momentum
v = y_momentum
w = z_momentum

ax.quiver(x, y, z,u,v,w, length=0.1, normalize=True)

plt.show()

this is the outcome of my code with the data provided

Nikaido
  • 4,443
  • 5
  • 30
  • 47
Stefano555
  • 31
  • 3
  • 1
    See [Adding colors to a 3d quiver plot in matplotlib](https://stackoverflow.com/questions/28420504/adding-colors-to-a-3d-quiver-plot-in-matplotlib) – JohanC Oct 24 '20 at 11:53
  • Here is an example of [how to set the limits of your 3D axes](https://stackoverflow.com/a/37522297/8881141). – Mr. T Oct 24 '20 at 12:02
  • thanks for the suggestion @JohanC but what I see from that post is that you can add a vector of rgb scale but I don't see any solution where you pass a vector of values and it does that automatically. – Stefano555 Oct 24 '20 at 12:04
  • With your data, you could try something like `q = ax.quiver(...., cmap='coolwarm', vmin=-1, vmax=1)` and `q.set_array(dot_product(uvw, preferred_gradient))`. If you'd provide some toy data (for example from the linked questions), it would be easier to show and test how it would work with your data. – JohanC Oct 24 '20 at 12:24
  • @JohanC would this solve point 2 (gradient related to the direction) or point 3 (gradient associated to the energy of each particle)? – Stefano555 Oct 24 '20 at 15:59
  • It would really really help if you added some test data. To relate the color to a direction, you could use a dot product. To relate it to the energy, you could use the energy itself, possibly scaled down to the range 0-1. – JohanC Oct 24 '20 at 18:16
  • dear @JohanC I added data related to 4 particles as you asked. – Stefano555 Oct 25 '20 at 11:20

0 Answers0