14
$\begingroup$

I'm having great difficulty understanding VectorScale. Here are the definitions from the documentation.

With the explicit specification VectorScale -> {unitlen,aratio,sfun} each field vector is constrained to fit in a vector box oriented in the direction of the field, centered at the location of the vector.

The unitlen is given as a fraction of the diagonal of the overall bounding box and is used as a local scale for vector boxes, aratio is the aspect ratio for vector boxes, sfun is a scaling function that determines the width of vector boxes.

I've used it with VectorPlot and have gotten the desired result, but I still just can't understand the above definitions. I've even read some authors saying "don't worry about how this works, but here is how you get a good picture." I just think I need to be a little more ready than that to explain things to my students.

Is it possible to draw a picture, maybe just a few arrows, and show their vector boxes surrounding them? And then explain the numbers used in the VectorScale option and how they relate to the size and shape of the vector boxes?

$\endgroup$
1
  • $\begingroup$ I tried to improve the format and fix possible typo, if I misunderstood some part of your question, feel free to roll back… Well, with all due respect, as a member for 2 years, you should have format this question better. $\endgroup$
    – xzczd
    Jan 17, 2015 at 3:59

2 Answers 2

14
+50
$\begingroup$

The option VectorPoints determines how many vector boxes there are. The plot domain is subdivided into a grid, whose grid points span the plot domain in each direction. Equal-size rectangular boxes surround each grid point so that the boxes are adjacent and tile the plot range (ignoring any padding).

Here is a picture with VectorPoints -> 9 (the default is 15):

VectorPlot[{x, y}, {x, -1, 1}, {y, -1, 1},
 VectorPoints -> 9, 
 GridLines -> With[{n = 8}, {#, #} &@Range[-1 - 1/n, 1 + 1/n, 2/n]]]

Mathematica graphics

Here is a utility function I'll use to explore various settings:

vsplot[unitlen_, aratio_: Automatic, sfun_: Automatic, vf_: {x, y}] :=
  VectorPlot[vf, {x, -1, 1}, {y, -1, 1},
  VectorPoints -> 9, 
  GridLines -> With[{n = 8}, {#, #} &@Range[-1 - 1/n, 1 + 1/n, 2/n]], 
  VectorScale -> {unitlen, aratio, sfun}]

unitlen

With unitlen = 1/9 (middle), the longest vector just fits in the box and the rest are scaled proportionally. Here the length is 1/9 the overall width of the domain, where the 9 is the number of PlotPoints. If using the default, the PlotPoints are 15 and the corresponding unitlen should be 1/15. Other settings are scaled versions of this, either exceeding the boundaries of the boxes or staying well within the box.

GraphicsRow@Table[vsplot[l], {l, {1/5, 1/9, 1/12}}]

Mathematica graphics

aratio

A numeric setting makes all arrowheads an absolute constant size. With Scaled[a], the size of the arrowhead depends on the length of the vector. @xzczd points out, aratio probably should be read as standing for "arrowhead ratio" and not "aspect ratio" as stated in the documentation for VectorScale.

GraphicsRow@Table[vsplot[1/9, a], {a, {1/2, 1, 2}}]

Mathematica graphics

GraphicsRow@Table[vsplot[1/9, Scaled[a]], {a, {1/2, 1, 2}}]

Mathematica graphics

sfun

The length of the vector is proportional to the value of sfun, which according to the documentation is to be

a function of x, y, fx, fy, Norm[{fx,fy}]

I'm not sure why one would want to change the vector length, other than to make them all the same length or perhaps use things like ArcTan[#5] & or Log[#5] & to attenuate the rapid growth of the length of the vectors of a vector field.

The columns below each show the same vector field scaled according to one of the arguments. The last pair are roughly inversely proportional to the length of the vector, which give somewhat misleading views of the actual vector fields.

GraphicsGrid@
 Table[Show[vsplot[1/9, Automatic, f, vf], 
   PlotLabel -> Row[{sfun, "=", f, ", ", {fx, fy}, "=", vf}], 
   ImageSize -> 200],
  {f, {#1 &, #2 &, #3 &, #4 &, 1/(1 + #5) &}},
  {vf, {{x, y}, {-y + x, y + x}}}]

Mathematica graphics

$\endgroup$
4
  • 1
    $\begingroup$ 1. Is "With unitlen = 1 (middle)" a typo? 2. So you think aratio is short for arrowhead ratio rather than aspect ratio? $\endgroup$
    – xzczd
    Feb 13, 2015 at 4:13
  • $\begingroup$ What a nice answer! +1 $\endgroup$
    – ciao
    Feb 13, 2015 at 9:08
  • 1
    $\begingroup$ @xzczd Yes a typo...of sorts. I think I mixed it up with aratio when I wrote it. Thanks. Now that you point it out, yes, I think "aspect ratio" must be a typo in the docs. I certainly think it's the arrowhead ratio, but I hadn't connected it with the a in aratio before. Thanks, again. :) $\endgroup$
    – Michael E2
    Feb 13, 2015 at 11:47
  • $\begingroup$ +1 Something like this should be included in the docs $\endgroup$ Feb 14, 2015 at 16:01
1
$\begingroup$

Get intuition from this:

Manipulate[
     VectorPlot[{Sin[x], Cos[y]}, {x, -Pi, Pi}, {y, -Pi, Pi}, 
     VectorScale -> {mysize, aratio}],
         {mysize, {Small, Medium, Large}},
          {aratio, .1, 1, .1}]

Here, mysize merely states how long a vector is (by gving a size of a bounding box). Here aratio ($0<aratio<1$) merely states the ratio of the size of the arrowhead to the length of the arrow line. My version (10.0.0) does not support sfun.

Or try this to get a box:

    Manipulate[
 VectorPlot[{-1 - x^2 + y, 1 + x - y^2},
  {x, -3, 3},
  {y, -3, 3},
  PlotRange -> {{-3, 3}, {-3, 3}},
  StreamPoints -> Coarse,
  StreamScale -> Full,
  VectorScale -> {unitlen, aratio, sfun},
  StreamStyle -> 
   Arrowheads[{{0.03, Automatic, 
      Graphics[{FaceForm[Yellow], EdgeForm[Directive[Thin, Red]], 
        Rectangle[1/unitlen {-sfun/2, -aratio/2}, 
         1/unitlen {sfun/2, aratio/2}]}]}}]],
 {unitlen, .1, 1},
 {aratio, .1, .5},
 {sfun, .1, 10}]
$\endgroup$
1
  • $\begingroup$ What do you mean by saying "My version (10.0.0) does not support sfun."? (You did set it in your second sample.) Anyway, +1, I didn't know StreamPoints etc. can be used inside VectorPlot! $\endgroup$
    – xzczd
    Feb 13, 2015 at 4:18

Your Answer

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

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