Message Boards Message Boards

0
|
3267 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Create logarithmically scaled arrows for vector plots?

Posted 4 years ago

I want to plot the following vector field in 2D, using the built in function VectorPlot: enter image description here Because the variation in modulus is typically several orders of magnitude, Mathematica's arrows are quite large near the source point, the point enter image description here, and are very short at the edge of the plot.

The way to solve this issue is to have the arrow lengths scaled logarithmically.

How can one do that in Mathematica? I came across the VectorScale option, and saw it accepts 3 arguments:

{unitlen,aratio,sfun}

As stated in the Documentation,

sfun is a scaling function that determines the width of vector boxes.

I think that the argument that is in interest for my purpose is sfun. But I need some help with writing down a command to be given there. Any help about it would be very appreciated.

POSTED BY: Ehud Behar
5 Replies
Posted 4 years ago

I gave another shot for this problem, as someone who (at least currently) works with Mathematica 11.

If one wants to get control over the length of the arrows in VectorPlot, the way to do it is call for the VectorScale option with a slot:

VectorPlot[
{vx,vy},
{x,y}\[Element]reg,
VectorScale -> {Automatic, Automatic, #}] 
& /@ {Function[Log10[#5]]}

The 5th slot is Norm[{fx,fy}]. But as the documentation to Mathematica 11 tells:

When using an explicit sfun, positive values are automatically scaled to lie between 0 and 1. For other values the vector is not drawn.

I.e. typing Log10 as I did wouldn't give good results in all cases. The correct scaling function for one's specific vector field and specific region of plotting is determined by the minimum value of Norm[{fx,fy}] (the shortest arrow in the plot) and maximum of Norm[{fx,fy}] (the longest arrow).

This makes the process of scaling vector field's arrows a task to ponder about each time drawing a vector field. I guess that Mathematica 12's new VectorScale arguments are designed to specifically skip and save you from all this math calculations.

The bottom line, as I see it, is not to fiddle with it the way I tried to, but rather to do it as @Gianluca Gorni did, tuck your vector field inside a scaling function.

Gianluca Gorni, thank you for your answer.

POSTED BY: Ehud Behar

Version 12.1 will start with a different default setting, which will greatly improve the default look of vector plots. The solution of Gianluca will suffice for now.

POSTED BY: Sander Huisman

Log may be too flattening. I would suggest to use ArcTan:

arctanElField[pt_, source_] := 
  ArcTan[1/Norm[pt - source]^2] Normalize[pt - source];
VectorPlot[arctanElField[{x, y}, {0, 0}], 
 Element[{x, y}, Annulus[{0, 0}, {1, 4}]]]
POSTED BY: Gianluca Gorni
Posted 4 years ago

@Gianluca Gorni Thanks a lot for your quick reply, but although your method does produce a vector plot with a rather nice scaling, it doesn't call for the VectorScale option I want to deploy. Could you address me on using this particular option?

POSTED BY: Ehud Behar

VectorScale is an option to VectorPlot that you can add freely:

arctanElField[pt_, source_] := 
  ArcTan[1/Norm[pt - source]^2]*Normalize[pt - source];
Manipulate[
 VectorPlot[arctanElField[{x, y}, {0, 0}],
  Element[{x, y}, Annulus[{0, 0}, {1, 4}]],
  VectorScale -> s],
 {{s, .05}, 0.001, .5}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract