ScottPlot.NET
GitHub Repo stars

Color

Color Quickstart

ScottPlot.Colors contains many colors

ScottPlot.Plot myPlot = new();

var circle1 = myPlot.Add.Circle(0, 0, 1);
var circle2 = myPlot.Add.Circle(1, 0, 1);
var circle3 = myPlot.Add.Circle(2, 0, 1);

circle1.FillColor = Colors.Red;
circle2.FillColor = Colors.Green;
circle3.FillColor = Colors.Blue;

// set outline style for all circles on the plot
foreach (var circle in myPlot.GetPlottables<ScottPlot.Plottables.Ellipse>())
    circle.LineColor = Colors.Black;

myPlot.SavePng("demo.png", 400, 300);

Creating Colors

ScottPlot.Colors can be constructed from RGB values (0-255), HTML style hexadecimal color codes (00-FF), or System.Drawing.Color objects.

ScottPlot.Plot myPlot = new();

var circle1 = myPlot.Add.Circle(0, 0, 1);
var circle2 = myPlot.Add.Circle(1, 0, 1);
var circle3 = myPlot.Add.Circle(2, 0, 1);

circle1.FillColor = new Color(red: 255, green: 0, blue: 0);
circle2.FillColor = new Color(System.Drawing.Color.Green);
circle3.FillColor = new Color("#0000FF");

// set outline style for all circles on the plot
foreach (var circle in myPlot.GetPlottables<ScottPlot.Plottables.Ellipse>())
    circle.LineColor = Colors.Black;

myPlot.SavePng("demo.png", 400, 300);

Alpha Channel

The Alpha channel sets transparency of a color

ScottPlot.Plot myPlot = new();

var circle1 = myPlot.Add.Circle(0, 0, 1);
var circle2 = myPlot.Add.Circle(1, 0, 1);
var circle3 = myPlot.Add.Circle(2, 0, 1);
var circle4 = myPlot.Add.Circle(3, 0, 1);

circle1.FillColor = new Color(red: 255, green: 0, blue: 0, alpha: 128);
circle2.FillColor = Colors.Green.WithAlpha(.5);
circle3.FillColor = Colors.Blue.WithAlpha(.5);
circle4.FillColor = Colors.Magenta.WithOpacity(Colors.Magenta.WithOpacity(0.9).Opacity / 2);

// set outline style for all circles on the plot
foreach (var circle in myPlot.GetPlottables<ScottPlot.Plottables.Ellipse>())
    circle.LineColor = Colors.Black;

myPlot.SavePng("demo.png", 400, 300);

Color Mixing

Colors have a MixWith() method that can be used to blend two colors

ScottPlot.Plot myPlot = new();

Color color1 = Colors.Blue;
Color color2 = Colors.Green;

for (int i = 0; i < 10; i++)
{
    var circle = myPlot.Add.Circle(i, 0, 1);
    double fraction = (double)i / 10;
    circle.FillColor = color1.MixedWith(color2, fraction);
    circle.LineColor = Colors.Black;
}

myPlot.SavePng("demo.png", 400, 300);

Color HSL

Colors may be generated from HSL (hue, saturation, luminosity) values.

ScottPlot.Plot myPlot = new();

for (int i = 0; i < 10; i++)
{
    var circle = myPlot.Add.Circle(i, 0, 1);
    float fraction = (float)i / 10;
    circle.FillColor = Color.FromHSL(hue: fraction, saturation: 1, luminosity: .5f);
    circle.LineColor = Colors.Black;
}

myPlot.SavePng("demo.png", 400, 300);

Interpolating Colors

A collection of colors can be generated from the linear interpolation between two colors.

ScottPlot.Plot myPlot = new();

Color[] colors = Color.InterpolateRgbArray(Colors.Blue, Colors.Green, steps: 20);

for (int i = 0; i < colors.Length; i++)
{
    var sig = myPlot.Add.Signal(Generate.Sin());
    sig.Data.XOffset = i * 3;
    sig.Data.YOffset = i * .1;
    sig.LineWidth = 3;
    sig.LineColor = colors[i];
}

myPlot.SavePng("demo.png", 400, 300);

Random Colors

The simplest way to generate random colors is to create colors which have same saturation and luminosity but random hue.

ScottPlot.Plot myPlot = new();

for (int i = 0; i < 20; i++)
{
    var sig = myPlot.Add.Signal(Generate.Sin());
    sig.Data.XOffset = i * 3;
    sig.Data.YOffset = i * .1;
    sig.LineWidth = 3;
    sig.LineColor = Color.RandomHue();
}

myPlot.SavePng("demo.png", 400, 300);

Colors from Colormap

Colormaps may be used to source a collection of colors.

ScottPlot.Plot myPlot = new();

IColormap colormap = new ScottPlot.Colormaps.Viridis();
Color[] colors = colormap.GetColors(20);

for (int i = 0; i < colors.Length; i++)
{
    var sig = myPlot.Add.Signal(Generate.Sin());
    sig.Data.XOffset = i * 3;
    sig.Data.YOffset = i * .1;
    sig.LineWidth = 3;
    sig.LineColor = colors[i];
}

myPlot.SavePng("demo.png", 400, 300);

Color Lighten and Darken

Helper methods make it easy to lighten or darken colors.

ScottPlot.Plot myPlot = new();

Color color1 = Colors.Blue;
Color color2 = Colors.Blue;

for (int i = 0; i < 10; i++)
{
    var circle1 = myPlot.Add.Circle(i, 3, 1);
    var circle2 = myPlot.Add.Circle(i, 0, 1);
    circle1.FillColor = color1;
    circle2.FillColor = color2;
    color1 = color1.Lighten(.2);
    color2 = color2.Darken(.2);
}

// set outline style for all circles on the plot
foreach (var circle in myPlot.GetPlottables<ScottPlot.Plottables.Ellipse>())
    circle.LineColor = Colors.Black;

myPlot.SavePng("demo.png", 400, 300);