ScottPlot.NET
GitHub Repo stars

Colormaps

A colormap is a continuous gradient of multiple colors. It can be used to color continuous data like heatmaps and images, but colormaps may also be sampled directly to create collections of colors. https://scottplot.net/cookbook/5/colormaps/ displays all colormaps included with ScottPlot.

ScottPlot.Plot myPlot = new();

var colormap1 = new ScottPlot.Colormaps.Viridis();
var colormap2 = colormap1.Invert();
var colormap3 = colormap1.InvertHue();

int steps = 20;
for (int x = 0; x < steps; x++)
{
    CoordinateRect rect1 = CoordinateRect.UnitSquare.WithTranslation(x, 4);
    CoordinateRect rect2 = CoordinateRect.UnitSquare.WithTranslation(x, 2);
    CoordinateRect rect3 = CoordinateRect.UnitSquare.WithTranslation(x, 0);
    var shape1 = myPlot.Add.Rectangle(rect1);
    var shape2 = myPlot.Add.Rectangle(rect2);
    var shape3 = myPlot.Add.Rectangle(rect3);

    // set color using the colormap
    double fraction = (double)x / (steps - 1);
    shape1.FillColor = colormap1.GetColor(fraction);
    shape2.FillColor = colormap2.GetColor(fraction);
    shape3.FillColor = colormap3.GetColor(fraction);

    shape1.LineColor = shape1.FillColor;
    shape2.LineColor = shape2.FillColor;
    shape3.LineColor = shape3.FillColor;
}

myPlot.Add.Text("Standard", 0, 5.5);
myPlot.Add.Text("Inverted", 0, 3.5);
myPlot.Add.Text("Inverted Hue", 0, 1.5);
myPlot.HideGrid();

myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Styling Plots category