# Color a vector field depending on the value of the component z of the vectors

I need to color this vector field. I want the vectors that have negative z component to be colored different that those ones with positive z component. This is the vector field:

table = Import["http://pastebin.com/raw/rjM2i5Jt", "Table", "IgnoreEmptyLines" -> True];

X = table[[;; , ;; 3]];
V = table[[;; , 4 ;; 6]];

g = Graphics3D[{[email protected], Arrow@Transpose[{X, X + .07 Normalize /@ V}]},
BoxRatios -> {1, 1, 1}, PlotRange -> All, ViewPoint -> {1, 1, 1},
ViewVertical -> {0, 1, 0}, Boxed -> False
]


Maybe

Graphics3D[{[email protected], {If[Subtract@@#[[;;,3]] <= 0, Red, Blue],
Arrow[#]}& /@ Transpose[{X, X + .07 Normalize /@ V}]},
BoxRatios -> {1, 1, 1}, PlotRange -> All, ViewPoint -> {1, 1, 1},
ViewVertical -> {0, 1, 0}, Boxed -> False]


• Thank you, now i would like to do the same in a 2d vector field. I graphic the cutting planes with these lines. Commented Oct 11, 2016 at 21:12
• table = Import["pastebin.com/raw/rjM2i5Jt", "Table", "IgnoreEmptyLines" -> True]; X = table[[;; , ;; 2]]; V = table[[;; , 4 ;; 5]]; Graphics [{[email protected], Arrow@Transpose[{X, X + .02 Normalize /@ V}]}] I would like to the same as before. Color the vectors to differentiate the ones that have postive z component from the others. Take account that here the x component is not in the graphic Commented Oct 11, 2016 at 21:17
• z component*... Commented Oct 11, 2016 at 21:18
• @Franco, does this give what you need: Graphics[{[email protected], {If[Subtract @@ #[[;; , 2]] <= 0, Red, Blue], Arrow[#]} & /@ Transpose[{X, X + .07 Normalize /@ V}]}]?
– kglr
Commented Oct 11, 2016 at 21:36
• Thank you again, you are solving all my problems! I will make the last question. Could i color the arrow with a gradient? In other words, color the arrows that have greater z component darker than the rest and keeping the two colors (negative and positives values). Commented Oct 11, 2016 at 22:00