GitHub Repo stars

.NET Interactive Notebook Quickstart

.NET Interactive Notebooks (polyglot notebooks) allow programmers to work with data in an interactive environment. To get started using ScottPlot to display data in a .NET notebook,

Create a new .NET Notebook

  • Install VS Code
  • Install the VS Code Polyglot Notebooks extension
  • Press CTRL + SHIFT + P to open the command dialogue
  • Select Polyglot Notebook: Create Default Notebook
  • Choose the .ipynb extension and select the C# language

Setup ScottPlot

Add this to the top of your notebook to use the ScottPlot NuGet package and make it easy to display plots inline:

This code sample is specific to ScottPlot 5 (details)
// Install the ScottPlot NuGet package
#r "nuget:ScottPlot, 5.0.*"

// Setup a custom formatter to display plots as images
using Microsoft.DotNet.Interactive.Formatting;
Formatter.Register(typeof(ScottPlot.Plot), (p, w) => 
    w.Write(((ScottPlot.Plot)p).GetImageHtml(400, 300)), HtmlFormatter.MimeType);

Linux users require an additional package as well

#r "nuget:SkiaSharp.NativeAssets.Linux.NoDependencies"

Plot Data

This code sample is specific to ScottPlot 5 (details)
// create sample data
double[] dataX = new double[] { 1, 2, 3, 4, 5 };
double[] dataY = new double[] { 1, 4, 9, 16, 25 };

// plot the data
ScottPlot.Plot plt = new();
plt.Add.Scatter(dataX, dataY);

// display the plot