5
$\begingroup$

I want to set all the lines in a VectorPlot a specific color, like Red. I am using some of the new options for VectorPlot as my code below illustrates. Using VectorColorFunction -> Red does not solve my problem.

Thank you for your assistance.

VectorPlot[{1, t - x}, {t, -2, 2}, {x, -2, 2}, VectorPoints -> 17, 
VectorScaling -> Automatic, VectorSizes -> 1.2, 
VectorStyle -> Arrowheads[0], VectorColorFunction -> Red]
$\endgroup$
0

3 Answers 3

5
$\begingroup$

I think this is what you're looking for:

VectorPlot[{1, t - x}, {t, -2, 2}, {x, -2, 2}, VectorPoints -> 17, 
 VectorScaling -> Automatic, VectorSizes -> 1.2, VectorStyle -> Red, 
 VectorMarkers -> "Segment", VectorColorFunction -> None]

enter image description here

  • VectorColorFunction -> None to not color the vectors by magnitude
  • VectorStyle -> Red to set the color
  • VectorMarkers -> "Segment to just get lines

(As an alternative to using VectorMarkers, you could also use VectorStyle -> Directive[Red, Arrowheads[0]].)

$\endgroup$
7
$\begingroup$

Replace Red with (Red &) in your code to get the desired result:

 VectorPlot[{1, t - x}, {t, -2, 2}, {x, -2, 2}, 
  VectorPoints -> 17, VectorScaling -> Automatic, VectorSizes -> 1.2, 
  VectorStyle -> Arrowheads[0], VectorColorFunction -> (Red &)]
 

enter image description here

From VectorColorFunction >> Details:

enter image description here

enter image description here

So to get a constant function that returns Red for all arguments we need to use Red& The parentheses in VectorColorFunction -> (Red &) is added because without parentheses this expression would be parsed as (VectorColorFunction -> Red) &.

$\endgroup$
1
$\begingroup$

The following example comes from the help of D entry:

   ClearAll["Global`*"]
    v[x_, y_] := {1, x - y}
    curl[{x_, y_}] = D[x + y, x] - D[x^2 y, y];
    Manipulate[
     VectorPlot[v[x, y], {x, -2, 2}, {y, -2, 2}, ImageSize -> Medium, 
      Epilog -> {If[curl[s] > 0, Green, Red], Thick, Dashed, Point[s], 
        Circle[s, Abs[curl[s]/3]]}], {{s, {0, 0}}, {-2, -2}, {2, 2}}, 
     SaveDefinitions -> True]

We can also specify multiple display colors by condition:

    f[x_, y_] := Evaluate[Curl[{1, x - y}, {x, y}]]
StreamPlot[{1, x - y}, {x, -2, 2}, {y, -2, 2}] /. {Arrowheads[spec_], 
   Arrow[pts_]} :> {Arrowheads[
    0.01*Abs[
      f[pts[[1, 1]], 
       pts[[1, 2]]]]], {If[(x - y /. {x -> pts[[1, 1]], 
         y -> pts[[1, 2]]}) > 0, Red, Black], Arrow[pts]}}

Or

VectorPlot[{1, t - x}, {t, -2, 2}, {x, -2, 2}, VectorPoints -> 17, 
 VectorScaling -> False, VectorSizes -> 1.2, 
 VectorColorFunctionScaling -> 
  False(*this option must be set to false*), 
 VectorStyle -> Arrowheads[0], 
 VectorColorFunction -> (Function[{x, y, vx, vy, r}, 
    If[x > 0 && y > 0, Red, Black]])]
$\endgroup$
2
  • 1
    $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – Kuba
    Commented Nov 17, 2020 at 11:50
  • $\begingroup$ @Kuba Thank you. I'm just joking with my acquaintances. Because my native language is not English, maybe there will be errors in the expression of tone. I won't do it next time. $\endgroup$ Commented Nov 18, 2020 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.