How to adjust vector scaling with a specific aspect ratio - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-22T04:49:40Z https://mathematica.stackexchange.com/feeds/question/103179 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/103179 1 How to adjust vector scaling with a specific aspect ratio Julie https://mathematica.stackexchange.com/users/36659 2016-01-01T22:21:02Z 2016-01-01T23:00:01Z <p>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.<br> This is my code</p> <pre><code>Show[VectorPlot[{If[y&gt;0, 1-2x, 1-x], If[y&gt;0, -6/25+2/5x-3/2y, -7/25+2/5x-1/2y]}, {x,0.49,0.8}, {y,-0.01,0.01}, VectorStyle-&gt;Black, VectorPoints-&gt;Coarse, VectorScale-&gt;{0.05, 1, None}, AspectRatio-&gt;0.62], ContourPlot[y==0, {x,0.48,0.8}, {y,-0.01,0.01}, ContourStyle-&gt;{Black}]] </code></pre> <p>which gives the following vector plot</p> <p><a href="https://i.stack.imgur.com/FrL0b.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FrL0b.jpg" alt="enter image description here"></a></p> <p>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</p> <pre><code>Show[VectorPlot[{If[y&gt;0, 1-2x, 1-x], If[y&gt;0, -6/25+2/5x-3/2y, -7/25+2/5x-1/2y]}, {x,0.49,0.8}, {y,-0.01,0.01}, VectorStyle-&gt;Black, VectorPoints-&gt;Coarse, VectorScale-&gt;{0.05, 1, #2&amp;}, AspectRatio-&gt;0.62], ContourPlot[y==0, {x,0.48,0.8}, {y,-0.01,0.01}, ContourStyle-&gt;{Black}]] </code></pre> <p>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.</p> <p><a href="https://i.stack.imgur.com/K3lgs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K3lgs.jpg" alt="enter image description here"></a></p> <p>Is there a way to scale the vectors so that this doesn't happen?</p> https://mathematica.stackexchange.com/questions/103179/-/103180#103180 3 Answer by Michael E2 for How to adjust vector scaling with a specific aspect ratio Michael E2 https://mathematica.stackexchange.com/users/4999 2016-01-01T23:00:01Z 2016-01-01T23:00:01Z <p>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 <code>PlotRange</code> and (2) according to the <code>AspectRatio</code>.</p> <pre><code>Show[VectorPlot[{If[y &gt; 0, 1 - 2 x, 1 - x], If[y &gt; 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 -&gt; Black, VectorPoints -&gt; Coarse, VectorScale -&gt; {1/20, 1, Function[{x, y, fx, fy, norm}, If[norm &gt; 0, norm/Sqrt[(fx/(0.8 - 0.49))^2 + (0.62 fy/(0.01 - (-0.01)))^2], 0]]}, AspectRatio -&gt; 0.62, PlotRange -&gt; All], ContourPlot[y == 0, {x, 0.48, 0.79}, {y, -0.01, 0.01}, ContourStyle -&gt; {Black}] ] </code></pre> <p><img src="https://i.stack.imgur.com/HBdbK.png" alt="Mathematica graphics"></p> <p>Note: Adding <code>PlotRange -&gt; All</code> was essential. <code>VectorPlot</code> was automatically extending the plot range, making it difficult to get the rescaling correct.</p>