绘图仪:标记
 

标记

可以在绘图的任何位置放置单个标记。

var plt = new ScottPlot.Plot(600, 400);

var colormap = ScottPlot.Drawing.Colormap.Turbo;
Random rand = new(0);
for (int i = 0; i < 100; i++)
{
    plt.AddMarker(
        x: rand.NextDouble(),
        y: rand.NextDouble(),
        size: 5 + rand.NextDouble() * 20,
        shape: Marker.Random(rand),
        color: colormap.RandomColor(rand));
}

plt.SaveFig("marker_quickstart.png");
 

可拖动标记器

存在一种特殊类型的标记,允许用鼠标拖动。

var plt = new ScottPlot.Plot(600, 400);

plt.AddSignal(ScottPlot.DataGen.Sin(51));
plt.AddSignal(ScottPlot.DataGen.Cos(51));

var myDraggableMarker = new ScottPlot.Plottable.DraggableMarkerPlot()
{
    X = 25,
    Y = .57,
    Color = Color.Magenta,
    MarkerShape = MarkerShape.filledDiamond,
    MarkerSize = 15,
    Text = "drag the point!",
};

myDraggableMarker.TextFont.Size = 16;

plt.Add(myDraggableMarker);

plt.SaveFig("marker_draggable.png");
 

可拖动标记捕捉

这是一种可以用鼠标拖动的标记,但仅限于由两个数组定义的X/Y位置。

var plt = new ScottPlot.Plot(600, 400);

// create random data and display it with a scatter plot
double[] xs = DataGen.Consecutive(50);
double[] ys = DataGen.Random(new Random(0), 50);
plt.AddScatter(xs, ys, label: "data");

// add a draggable marker that "snaps" to data values in that scatter plot
var dmpv = new ScottPlot.Plottable.DraggableMarkerPlotInVector()
{
    Xs = xs,
    Ys = ys,
    DragEnabled = true,
    IsVisible = true,
    MarkerSize = 15,
    MarkerShape = MarkerShape.filledDiamond,
    MarkerColor = Color.Magenta,
    Label = "marker",
};
plt.Add(dmpv);

plt.Legend();

plt.SaveFig("marker_draggableinvector.png");
 

标记标记

标记有一个可选的文本标签。

var plt = new ScottPlot.Plot(600, 400);

plt.AddSignal(DataGen.Sin(51));

var marker = plt.AddMarker(35, 0.6);
marker.Text = "Interesting Point";
marker.TextFont.Color = Color.Magenta;
marker.TextFont.Alignment = Alignment.UpperCenter;
marker.TextFont.Size = 28;

plt.SaveFig("marker_labeled.png");
 

标记线宽度

标记具有可自定义的选项,例如线宽。

var plt = new ScottPlot.Plot(600, 400);

double[] ys1 = DataGen.Sin(30);
var cmap1 = ScottPlot.Drawing.Colormap.Viridis;

double[] ys2 = DataGen.Cos(30);
var cmap2 = ScottPlot.Drawing.Colormap.Turbo;

for (int i = 0; i < ys1.Length; i++)
{
    double frac = i / (ys1.Length - 1f);

    var circle = plt.AddMarker(i, ys1[i]);
    circle.MarkerShape = MarkerShape.openCircle;
    circle.MarkerSize = i + 5;
    circle.MarkerLineWidth = 1 + i / 2;
    circle.MarkerColor = cmap1.GetColor(1 - frac, .8);

    var triangle = plt.AddMarker(i, ys2[i]);
    triangle.MarkerShape = MarkerShape.openTriangleUp;
    triangle.MarkerSize = i + 5;
    triangle.MarkerLineWidth = 1 + i / 4;
    triangle.MarkerColor = cmap2.GetColor(frac, .8);
}

plt.Margins(.2, .2);

plt.SaveFig("marker_linewidth.png");