1
$\begingroup$

I'm trying to create a vector plot with uniform vector scaling. I need the x and y ranges to be very different, because I need to highlight the angle between the vectors and the y=0 axis. This means that I can't use an automatic aspect ratio, however, changing the aspect ratio is changing the vector scaling in a way that I don't understand.
This is my code

Show[VectorPlot[{If[y>0, 1-2x, 1-x], If[y>0, -6/25+2/5x-3/2y, -7/25+2/5x-1/2y]},
{x,0.49,0.8}, {y,-0.01,0.01}, VectorStyle->Black, VectorPoints->Coarse, 
VectorScale->{0.05, 1, None}, AspectRatio->0.62], 
ContourPlot[y==0, {x,0.48,0.8}, {y,-0.01,0.01}, ContourStyle->{Black}]]

which gives the following vector plot

enter image description here

I specifically need the arrows on the top left to be approximately the same size as the rest of them, and to not cross the y=0 axis. I've also entered specific functions into sfun, for instance

Show[VectorPlot[{If[y>0, 1-2x, 1-x], If[y>0, -6/25+2/5x-3/2y, -7/25+2/5x-1/2y]},
{x,0.49,0.8}, {y,-0.01,0.01}, VectorStyle->Black, VectorPoints->Coarse, 
VectorScale->{0.05, 1, #2&}, AspectRatio->0.62], 
ContourPlot[y==0, {x,0.48,0.8}, {y,-0.01,0.01}, ContourStyle->{Black}]]

which should give a uniform vector length for the same y values, but instead gives the picture below, where there is the same vector length problem in the upper left corner.

enter image description here

Is there a way to scale the vectors so that this doesn't happen?

$\endgroup$
4
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Jan 1, 2016 at 22:25
  • 3
    $\begingroup$ See mathematica.stackexchange.com/questions/71787/… $\endgroup$
    – Michael E2
    Jan 1, 2016 at 22:30
  • $\begingroup$ I don't think it is really a duplicate. It turned out that figuring out the rescaling was a bit tricky, esp. because VectorPlot was changing the plot range so that it didn't not match the plot domain. See my answer. $\endgroup$
    – Michael E2
    Jan 1, 2016 at 23:06
  • $\begingroup$ Similar: mathematica.stackexchange.com/a/32613 $\endgroup$
    – Michael E2
    Jan 1, 2016 at 23:22

1 Answer 1

4
$\begingroup$

You have to scale the (x,y)-components of the vectors so that they correspond to the horizontal and vertical units on the screen. That means scaling (1) according to the PlotRange and (2) according to the AspectRatio.

Show[VectorPlot[{If[y > 0, 1 - 2 x, 1 - x], 
   If[y > 0, -6/25 + 2/5 x - 3/2 y, -7/25 + 2/5 x - 1/2 y]}, {x, 0.49,
    0.8}, {y, -0.01, 0.01},
  VectorStyle -> Black, VectorPoints -> Coarse,
  VectorScale -> {1/20, 1, 
    Function[{x, y, fx, fy, norm}, 
     If[norm > 0, 
      norm/Sqrt[(fx/(0.8 - 0.49))^2 + (0.62 fy/(0.01 - (-0.01)))^2], 
      0]]},
  AspectRatio -> 0.62, PlotRange -> All],
 ContourPlot[y == 0, {x, 0.48, 0.79}, {y, -0.01, 0.01}, 
  ContourStyle -> {Black}]
 ]

Mathematica graphics

Note: Adding PlotRange -> All was essential. VectorPlot was automatically extending the plot range, making it difficult to get the rescaling correct.

$\endgroup$

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.