How to create an interactive plot in a C# Avalonia application

Step 1: Install the ScottPlot.Avalonia NuGet package

Step 2: Import the ScottPlot.Avalonia namespace by adding this to your Window element:


Your Window element should look something like this:

<Window xmlns=""
        <!-- More attributes -->
        Title="Avalonia Quickstart" Width="500" Height="350">

Step 3: Add an AvaPlot to your layout and give it a unique name

<ScottPlot:AvaPlot Name="AvaPlot1"/>

Step 4: Plot some data in your start-up sequence

double[] dataX = new double[] { 1, 2, 3, 4, 5 };
double[] dataY = new double[] { 1, 4, 9, 16, 25 };
AvaPlot avaPlot1 = this.Find<AvaPlot>("AvaPlot1");
avaPlot1.Plot.AddScatter(dataX, dataY);

MacOS & Linux

ScottPlot relies on System.Drawing.Common which requires libgdiplus on non-Windows systems:

  • MacOS: brew install mono-libgdiplus

  • Linux: apt-get install -y libgdiplus

You may also need to specifically add the System.Drawing.Common package to your project:

dotnet add package System.Drawing.Common