XY Plot - Custom color per marker/pixel?

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

bradparks wrote at 2013-08-27 15:57:

Hi there;

I've just found this excellent looking library and have looked at the examples, but don't see anything that matches what I'd like to do:

I need to do a plot of thousands of x,y coordinates, each as a stand alone point with a custom color per pixel. The colors will range over 1000's of colors as well (possibly a custom color for each individual pixel)

What type of plot and marker type would I use to do this?

I saw the custom marker types example, but that only seems to allow one custom market type per series. I also took a look at the mouse move examples, and they got that to work by creating a custom series for each mouse movement, which isn't really what I want (way too many series). My data comes in batches, and will probably be in ~10 batches, and each batch will be a custom series, I expect.



everytimer wrote at 2013-08-27 22:54:

I don't think it's possible right now. As you said you can create a new ScatterSeries/LineSeries for each group of points with the same color.

If you can use the MatrixSeries provided in the examples you can change it partially:
   if (this.image == null)
                var pixels = new OxyColor[m, n];
                for (int i = 0; i < m; i++)
                    for (int j = 0; j < n; j++)

                        var c = MyColorSelectionMethod(Matrix[m-1-i, j]);

                        pixels[i, j] = Math.Abs(this.Matrix[m - 1 - i, j]) <= this.ZeroTolerance ? OxyColors.Transparent : c;
                        //pixels[i, j] = Math.Abs(this.Matrix[m - 1 - i, j]) <= this.ZeroTolerance ? OxyColors.Transparent : this.NotZeroColor;

                this.image = OxyImage.PngFromArgb(pixels);
And the custom method could be:

        public static OxyColor MyColorSelectionMethod(double num)
            OxyColor color = new OxyColor();
            IList<OxyColor> listColors = new List<OxyColor>();
            OxyColor c;
            for (double i = 0; i < 1; i += 0.02)
                c = OxyColor.FromHsv(i, 0.8, 0.8);

            if (num > 0.7)
                color = listColors[Convert.ToInt32(num * 49)];
                color = listColors[Convert.ToInt32(num * 49)].ChangeAlpha((byte)(100*num));


            return color;
This method assigns a color from gradient depending on the value of "num". Note that in this example I've set its maximum value to 1.

Result: Image

bradparks wrote at 2013-08-28 15:09:

Hmmm... interesting! thanks for the code and suggestions.... I'll take a look and see what I can make of it.... thanks for your help!