.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 + Pto open the command dialogue - Select Polyglot Notebook: Create Default Notebook
- Choose the
.ipynbextension and select the C# language
Add the ScottPlot Package
Add this to the top of your notebook:
#r "nuget:ScottPlot, 5.0.*"
Linux users may require an additional package:
#r "nuget:SkiaSharp.NativeAssets.Linux.NoDependencies"
Prepare a Plot Viewer
using Microsoft.DotNet.Interactive.Formatting;
Formatter.Register(typeof(ScottPlot.Plot), (p, w) =>
w.Write(((ScottPlot.Plot)p).GetPngHtml(400, 300)), HtmlFormatter.MimeType);
Plot Data
// 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
plt
