Skip to content

Colormap: shortcut to get a range of colors#3983

Merged
swharden merged 5 commits intoScottPlot:mainfrom
CoderPM2011:feat/GetColors
Jun 25, 2024
Merged

Colormap: shortcut to get a range of colors#3983
swharden merged 5 commits intoScottPlot:mainfrom
CoderPM2011:feat/GetColors

Conversation

@CoderPM2011
Copy link
Contributor

I implemented a slightly different version of the GetColors method in IColormapExtensions based on #3947.
I'm not sure if this meets the requirements of #3947, so feel free to make changes.

@swharden
Copy link
Member

Thanks for this PR @CoderPM2011! I'm refining the behavior slightly and adding a cookbook recipe to demonstrate this new feature. I'm excited to have this in the next release! 🚀

IColormap colormap = new ScottPlot.Colormaps.Turbo();

for (int count = 1; count < 10; count++)
{
    double[] xs = Generate.Consecutive(count);
    double[] ys = Generate.Repeating(count, count);
    Color[] colors = colormap.GetColors(count);

    for (int i = 0; i < count; i++)
    {
        var circle = myPlot.Add.Circle(xs[i], ys[i], 0.45);
        circle.FillColor = colors[i];
        circle.LineWidth = 0;
    }
}

image

@swharden swharden linked an issue Jun 25, 2024 that may be closed by this pull request
@swharden swharden enabled auto-merge (squash) June 25, 2024 01:58
@swharden swharden merged commit b38f41a into ScottPlot:main Jun 25, 2024
@CoderPM2011 CoderPM2011 deleted the feat/GetColors branch June 25, 2024 02:07
KroMignon added a commit to KroMignon/ScottPlot that referenced this pull request Jun 26, 2024
* upstream/main:
  Fix interaction of axis panels when scale factor is more than 1 (ScottPlot#3994)
  Added ResetMinAndMaxValues() to DataLoggerSource.cs (ScottPlot#3993)
  CoordinateLine: add constructor overloads (ScottPlot#3987)
  Colormap.GetColors() (ScottPlot#3983)
  Added a constructor overload that accepts List<Coordinates> (ScottPlot#3982)
  Signal: improve support for IReadOnlyList<T> (ScottPlot#3978)
  Axes: improve sharpness of axis lines, tick marks, and grid lines (ScottPlot#3976)
  adding console write file name function (ScottPlot#3965)
  Color.ToColor()
  Sandbox: extend minimal API
  Sandbox: Create .NET API project
  SVG XML Updates (ScottPlot#3957)
  Repeat render if changes are made in invoked events (ScottPlot#3952)
  CI: autoformat
  Experimental DataLogger2 using a `CircularBuffer<T>` (ScottPlot#3946)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Colormap: shortcut to get a range of colors

2 participants