# Combining Plot with VectorPlot

I'm trying to combine the plot of a function with a vector plot, but no matter what option I choose for VectorPoints, the resulting combined plot just looks ridiculous. For example, the combined plot with the "VectorPoints -> Coarse" option looks like this: What I actually want is just one vector plot line with small arrows that sits slightly above the solid red line of the function, and one that sits slightly below it.

Edit 1: this is the combined plot using StreamPlot instead of VectorPlot with the same parameters, i.e.

spfig = StreamPlot[{1, f[x, y]}, {x, 40, 75}, {y, 1, 5}, StreamPoints -> Coarse];
Show[fig1, spfig] Edit 2: here is a MWE:

F[x_, y_] := 1 - (2 (64 - x)^(1/3) y[x]^2)/(2 (64 - x)^(1/3) + y[x]^3);
Eq = D[y[x], x] == F[x, y]/2 // Simplify;
NDSolveRes = NDSolve[{Eq, y[53.854] == 2.632}, y, {x, 0, 70}];
fig1 = Plot[y[x] /. NDSolveRes, {x, 0, 90}, AxesLabel -> {"x", "y"}, PlotStyle -> {Darker[Red], Thickness -> 0.003}];
f[x_, y_] := 1/2 - (y^2 (64 - x)^(1/3))/(y^3 + 2 (64 - x)^(1/3));
vpfig = VectorPlot[{1, f[x, y]}, {x, 40, 75}, {y, 1, 5}, VectorPoints -> Coarse];
Show[fig1, vpfig]


Edit 3: here are the error messages: • You might want to look into StreamPlot with the StreamPoints option. Sep 22, 2021 at 9:17
• I have, but the lines of the StreamPlot differ significantly from those of the VectorPlot. I have attached another figure to my original post showing the output of StreamPlot using the exact same function and parameters as for VectorPlot. Sep 22, 2021 at 9:31
• Please provide the function definition and what you used to plot the red curve. Can you plot each over the same range and then use Show?
– Moo
Sep 22, 2021 at 10:49
• I've added a MWE, see edit 2 at the end of my original post. Sep 22, 2021 at 12:52

You should be able to use VectorPoints where you define the points you want instead of using Coarse

F[x_, y_] := 1 - (2 (64 - x)^(1/3) y[x]^2)/(2 (64 - x)^(1/3) + y[x]^3)
Eq = D[y[x], x] == F[x, y]/2 // Simplify
NDSolveRes = NDSolve[{Eq, y[53.854] == 2.632}, y, {x, 0, 70}]
xs = Range[40, 70]
ys = Flatten[Table[Re[Evaluate[y[x]] /. NDSolveRes], {x, 40, 70}]]
upperPoints = Transpose[{xs, ys + .3}]
lowerPoints = Transpose[{xs, ys - .3}]
fig1 = Plot[y[x] /. NDSolveRes, {x, 0, 90}, AxesLabel -> {"x", "y"},
PlotStyle -> {Darker[Red], Thickness -> 0.003}]
f[x_, y_] := 1/2 - (y^2 (64 - x)^(1/3))/(y^3 + 2 (64 - x)^(1/3))
vpfig1 = VectorPlot[{1, f[x, y]}, {x, 40, 75}, {y, 1, 5},
VectorPoints -> lowerPoints]
vpfig2 = VectorPlot[{1, f[x, y]}, {x, 40, 75}, {y, 1, 5},
VectorPoints -> upperPoints]
Show[fig1, vpfig1, vpfig2] You can change the arrow properties as you see fit for better scaling and such.

EDIT:

Here's a version with better scaling that puts the upper and lower arrows along the entire line

F[x_, y_] := 1 - (2 (64 - x)^(1/3) y[x]^2)/(2 (64 - x)^(1/3) + y[x]^3)
Eq = D[y[x], x] == F[x, y]/2 // Simplify
NDSolveRes = NDSolve[{Eq, y[53.854] == 2.632}, y, {x, 0, 70}]
xs = Range[0, 70, 4]
ys = Flatten[Table[Re[Evaluate[y[x]] /. NDSolveRes], {x, 0, 70, 4}]]
upperPoints = Transpose[{xs, ys + .3}]
lowerPoints = Transpose[{xs, ys - .3}]
fig1 = Plot[y[x] /. NDSolveRes, {x, 0, 90}, AxesLabel -> {"x", "y"},
PlotStyle -> {Darker[Red], Thickness -> 0.003}]
f[x_, y_] := 1/2 - (y^2 (64 - x)^(1/3))/(y^3 + 2 (64 - x)^(1/3))
vpfig1 = VectorPlot[{1, f[x, y]}, {x, 0, 75}, {y, 0, 8},
VectorPoints -> lowerPoints, VectorAspectRatio -> .1,
VectorSizes -> .6, VectorColorFunction -> None, VectorStyle -> Blue]
vpfig2 = VectorPlot[{1, f[x, y]}, {x, 0, 75}, {y, 0, 8},
VectorPoints -> upperPoints, VectorAspectRatio -> .1,
VectorSizes -> .6, VectorColorFunction -> None, VectorStyle -> Blue]
Show[fig1, vpfig1, vpfig2] • Thank you! How exactly do I change the arrow properties? Ideally, I would like to decrease the density/frequency of arrows to only 6-7 arrows for each line (upper and lower) and make the arrowheads smaller. I've tried xs = Range[40, 70,4] to increase the step size but I can't figure out how to make it compatible with the flattened table. Also, I've tried "VectorScaling->" and "VectorSizes->" in the VectorPlot[] bracket (as illustrated here: reference.wolfram.com/language/ref/VectorPlot.html), but it seems that these commands are not recognised for some reason (text turned red)?? Sep 22, 2021 at 15:46
• Try adding VectorAspectRatio -> .1, VectorSizes -> .6 to the VectorPlots. For the spacing you can do 40,70,4 in both the xs and in the ys and it'll space out the points.xs = Range[40, 70, 4] and ys = Flatten[Table[Re[Evaluate[y[x]] /. NDSolveRes], {x, 40, 70, 4}]] Sep 22, 2021 at 18:54
• @ConfusedCabbage See my edit Sep 22, 2021 at 19:01
• I've copied the code from your edit, but "VectorAspectRatio -> .1" and "VectorSizes -> .6" are highlighted in red and I'm getting errors, see screenshot in edit 3 at the end of my original post. Sep 22, 2021 at 22:51
• Never mind. I found a way to do it: specifying PlotRange->{{0,90},{0,9}} in fig1 and plotting fig1 first in Show[] keeps the range fixed to $x \in \left[0,90\right]$ and $y \in \left[0,9\right]$. Thanks again for your help! Sep 23, 2021 at 4:14