Vector Field
Vectors (representing a magnitude and direction) can be placed at specific points in coordinate space to display as a vector field.
ScottPlot.Plot myPlot = new();
// generate a grid of positions
double[] xs = Generate.Consecutive(10);
double[] ys = Generate.Consecutive(10);
// create a collection of vectors
List<RootedCoordinateVector> vectors = new();
for (int i = 0; i < xs.Length; i++)
{
for (int j = 0; j < ys.Length; j++)
{
// point on the grid
Coordinates pt = new(xs[i], ys[j]);
// direction & magnitude
float dX = (float)ys[j];
float dY = -9.81f / 0.5f * (float)Math.Sin(xs[i]);
System.Numerics.Vector2 v = new(dX, dY);
// add to the collection
RootedCoordinateVector vector = new(pt, v);
vectors.Add(vector);
}
}
// plot the collection of rooted vectors as a vector field
myPlot.Add.VectorField(vectors);
myPlot.SavePng("demo.png", 400, 300);
Vector field arrows can be colored according to their magnitude.
ScottPlot.Plot myPlot = new();
RootedCoordinateVector[] vectors = Generate.SampleVectors();
var vf = myPlot.Add.VectorField(vectors);
vf.Colormap = new ScottPlot.Colormaps.Turbo();
myPlot.SavePng("demo.png", 400, 300);
Length of arrows in a vector field may be customized by defining length (in pixel units) to display the longest vector.
ScottPlot.Plot myPlot = new();
RootedCoordinateVector[] vectors = Generate.SampleVectors();
var vf = myPlot.Add.VectorField(vectors);
vf.MaximumArrowLength = 15;
myPlot.SavePng("demo.png", 400, 300);


