Plottable Management
Although the Plot.Add class has many helpful methods for creating plottable objects and adding them to the plot, users can instantiate plottable objects themselves and use Add.Plottable() to place it on the plot. This strategy allows users to create their own plottables (implementing IPlottable) with custom appearance or behavior.
ScottPlot.Plot myPlot = new();
// create a plottable and modify it as desired
ScottPlot.Plottables.LinePlot line = new()
{
Start = new Coordinates(1, 2),
End = new Coordinates(3, 4),
};
// add the custom plottable to the plot
myPlot.Add.Plottable(line);
myPlot.SavePng("demo.png", 400, 300);
Use Clear() to remove all plottables.
ScottPlot.Plot myPlot = new();
// add plottables
myPlot.Add.Signal(Generate.Sin());
myPlot.Add.Signal(Generate.Cos());
// remove all plottables
myPlot.Clear();
myPlot.SavePng("demo.png", 400, 300);
Individual items may be removed from the plot.
ScottPlot.Plot myPlot = new();
// add plottables
var sig1 = myPlot.Add.Signal(Generate.Sin());
var sig2 = myPlot.Add.Signal(Generate.Cos());
// remove a specific plottable
myPlot.Remove(sig1);
myPlot.SavePng("demo.png", 400, 300);
All plottables of a given type may be removed from a plot with a single command.
ScottPlot.Plot myPlot = new();
myPlot.Add.Scatter(Generate.Consecutive(51), Generate.Sin(51));
myPlot.Add.Signal(Generate.Cos());
myPlot.Add.HorizontalLine(0.75);
// remove every instance of a specific plottable type
myPlot.Remove<ScottPlot.Plottables.Signal>();
myPlot.SavePng("demo.png", 400, 300);
The plottable list contains all plottables which will be rendered in order. Helper methods are available to move plottables to the front.
ScottPlot.Plot myPlot = new();
CoordinateRect wideRect = new(-2, 2, -1, 1);
CoordinateRect tallRect = new(-1, 1, -2, 2);
// rect1 is added first, so plottables added later will appear on top
var rect1 = myPlot.Add.Rectangle(wideRect);
var rect2 = myPlot.Add.Rectangle(tallRect);
// plottables may be moved to the front so they always appear on top
myPlot.MoveToTop(rect1);
myPlot.SavePng("demo.png", 400, 300);




