ScottPlot.NET
GitHub Repo stars

Animated GIF Plot

Animated GIFs can be created from ScottPlot plots!

This example requires these NuGet packages:

using ImageMagick;

using (var collection = new MagickImageCollection())
{
    ScottPlot.Plot plot = new();
    for (int i = 1; i <= 10; i++)
    {
        double[] values = ScottPlot.Generate.Sin(100, phase: -i * .05);
        plot.Add.Signal(values);
        byte[] bytes = plot.GetImageBytes(400, 300);
        MagickImage image = new(bytes) { AnimationDelay = 20 };
        collection.Add(image);
    }

    collection.Optimize();

    using var outputStream = new MemoryStream();
    collection.Write(outputStream, MagickFormat.Gif);
    byte[] gifBytes = outputStream.ToArray();
    File.WriteAllBytes("animated.gif", gifBytes);
}