I'd like to plot a vector field with a legend for the magnitude of a reference vector. I have read all the document of VectorPlot
and found only PlotLegends
is possible for this purpose. But I cannot come up with a solution. I also found a similar question here without the desired solution. So I post a minimal question here. Note that I do not want to visualize the magnitudes with colors, so please do not waste your time.
Question: How can I plot a vector field with a reference legend showing the reference magnitude? For example, in this figure, the arrow length of the legend should be related to that of the vector field to indicate a reference length.
VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> {"Ref. vector"}]
InputForm[VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> {"Ref. vector"}]]
you will see thatPlotLegend
is formed from an arrow of unit lengthArrow[{{0, 0.5}, {1, 0.5}}]
placedAfter
. So, this unit arrow has reference length, in some sense at least. $\endgroup$VectorColorFunction -> "Rainbow", PlotLegends -> Automatic
? $\endgroup$Maximize[{Norm[{y, -x}], -3 <= x <= 3 && -3 <= y <= 3}, {x, y}] // First = 3 Sqrt[2]
. Lengths of vectors are scaled to the diagonal of the plot range, in your case this is6*Sqrt[2]
. So, usingVectorScale
option andLegended
:Legended[VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}, VectorScale -> {0.5, 0.1}], Graphics[{Arrowheads[0.3], Arrow[{{0, 0}, {1/(3 Sqrt[2]), 0}}]}]]
. $\endgroup$