Search code examples
colorsplotlimitaxisilnumerics

Fixed color level (Z axis) in ILPlotCube. (ILNumerics)


I want to show some plot in a player. I want to show it with the same scale of Z axis, so the color will change automatically (instead of min & max value). Here is my function.

    private void PlaySaturationButton_Click(object sender, EventArgs e)
    {
        float Zmin = (float) Sw.Min();
        float Zmax = (float) Sw.Max();

        for (int i = 1; i < n_time; i++)
        {
            var scene = new ILScene();
            var plotCube = scene.Add(new ILPlotCube(twoDMode: false));


            plotCube.Limits.ZMin = Zmin;
            plotCube.Limits.ZMax = Zmax;
            plotCube.AspectRatioMode = AspectRatioMode.MaintainRatios;

            ILColormap cm = new ILColormap(Colormaps.Jet);
            ILArray<float> data = cm.Data;

            plotCube.Add(new ILSurface(ILMath.tosingle(Sw[":;:;" + (i - 1) + ""])){
                    Wireframe = { Color = Color.FromArgb(50, Color.LightGray)},
                    Colormap = new ILColormap(data),
                    Children = { new ILColorbar()}}
                    );

            SaturationilPanel.Scene = scene;
            SaturationilPanel.Refresh();
            System.Threading.Thread.Sleep(50);
        }
    }

But it get me the wrong answer. In this function, min & max of color level still change. The color itself stayed static. Where is my mistake?

Update:

enter image description here

As we can see at the above image, there is a button named "play". When we click that button, it will executing the function that I described before. I want to see the changes of our data by "re-plotting" the data for each frame.

I was thoughts, if I adjust the limit Z (max and min) value with same number for each frame, it will also updating the color scale. It seems that I was wrong when I read this: Same color bar for multiple surfaces in ILNumerics PlotCube and http://ilnumerics.net/managing-colormaps.html. It seems that the color scale is not directly correlated with the Z scale of ILPlotCube. Does it wrong?

However, I still struggling with it. I am not yet get the concept about coloring in ILNumerics.

What I want to achieve at the moment is, I want to have a picture with the same color scale for each frame.


Solution

  • Instead of recreating the surface in each handler call, you should reuse it! Even if it is not related to your question, recreation is extremly slow in comparison to reusing a surface.

    In order to update the surface and make it use the same data range always, you could do:

    ilPanel1.Scene.First<ILSurface>().UpdateColormapped(A, dataRange: Tuple.Create(-1f, 1f)); 
    

    datarange specifies an individual data range used for mapping data values to colormap colors. By default, the min and max values from the data are mapped to the lower and upper end of the colormap. datarange gives you the chance to override this and use individual limits instead.

    In order for several surfaces to share the same colors, based on the same colormap, one needs to supply the same values for datarange for each surface.