4
$\begingroup$

I'm trying to plot a vector field over the range $[-1, 1]\times [-1, 1]$, but only outside the circle of radius 0.2 centered at the origin. The function diverges at the origin so the magnitude of all the other arrows is tiny in comparison. I've restricted the plot range using RegionFunction->Function[{x, y, vx, vy, n}, x^2+y^2>0.2], but it doesn't affect the scaling, (I couldn't get it scaling manually either.) A simple example in the style of what I want to do is:

VectorPlot[{1/Sqrt[x^2 + y^2], 1/ Sqrt[x^2 + y^2]}, {x, -1, 1}, {y, -1, 1}, 
 RegionFunction -> Function[{x, y, vx, vy, n}, x^2 + y^2 > 0.2], 
 VectorScale -> Large]

But with the arrows only scaled based on their values outside the circle of radius 0.2.

Any advice would be much appreciated.

$\endgroup$
3
  • $\begingroup$ You can play with options, like there: Plotting a Gravity-Field and in linked topics. $\endgroup$
    – Kuba
    Commented Jan 14, 2016 at 17:55
  • $\begingroup$ A circle of radius 0.2 is defined by x^2 + y^2 > 0.2^2, not x^2 + y^2 > 0.2. $\endgroup$
    – user484
    Commented Jan 15, 2016 at 0:51
  • $\begingroup$ @Rahul, yes, silly typo on my part there when writing out the post. Thanks for pointing it out in case I'd messed that up. $\endgroup$
    – Goobley
    Commented Jan 15, 2016 at 12:39

2 Answers 2

2
$\begingroup$
VectorPlot[
 If[x^2 + y^2 > .2, {1/Sqrt[x^2 + y^2], 1/Sqrt[x^2 + y^2]}, 0], 
 {x, -1, 1}, {y, -1, 1}, 
 RegionFunction -> Function[{x, y}, x^2 + y^2 > 0.2], 
 VectorScale -> Large]

enter image description here

or...

VectorPlot[
   If[x^2 + y^2 > .2, {1/Sqrt[x^2 + y^2], 1/Sqrt[x^2 + y^2]}, {0, 0}], 
   {x, -1, 1}, {y, -1, 1}, 
   VectorScale -> Large]
$\endgroup$
2
  • $\begingroup$ Just look! A NKPT! (New Kind of Pythagorean Theorem) :) $\endgroup$ Commented Jan 14, 2016 at 18:14
  • $\begingroup$ Brilliant, didn't think of composing a conditional. Thanks very much. $\endgroup$
    – Goobley
    Commented Jan 14, 2016 at 18:26
1
$\begingroup$
VectorPlot[{1/Sqrt[x^2 + y^2], 1/Sqrt[x^2 + y^2]}, 
 {x, -1, 1}, {y, -1, 1},
 PlotRange -> 1.1,
 RegionFunction -> Function[{x, y}, x^2 + y^2 > 0.2],
 VectorPoints -> Coarse,
 VectorScale -> 0.5]

enter image description here

$\endgroup$

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.