Industrial Data Science
in C# and .NET:
Simple. Fast. Reliable.
 
 

ILNumerics - Technical Computing

Modern High Performance Tools for Technical

Computing and Visualization in Industry and Science

Colormapped Circles with PlotCube


The example creates a number of circle objects, based on ILNumerics.Drawing.Circle. The circles are placed within a PlotCube instance and are displayed as plotting objects. Scaling and axis handling works just like for regular plot objects.

The fill color for the circles is determined by mapping a certain value associated to them to a color by help of a colormap. For this example, the distance of the circle to the center in the X/Y plane is used for selecting a color from the colormap.

A colorbar is created and displayed next to the plot cube. It shows the range of values and the colors assigned to them.

Note how the circles receive regular plotting features: the functionality of the plot cube is retained (rotation, panning etc.). Also, the circles are placed in 3D space, hence become assigned a z-position: their order is clearly visible when rotating the plot cube.

Last modified: August 26 2021 09:17

Download ZIP

Change Code ⇾ Press Play
Colormapped Circles with PlotCube
 
 
C#-Code
using System;
1
using System;
2
using System.Drawing;
3
using System.Windows.Forms;
4
using ILNumerics;
5
using ILNumerics.Drawing;
6
using ILNumerics.Drawing.Plotting;
7
 
8
namespace ColormappedCircles_inPlotCube {
9
    public partial class Form1 : Form {
10
        public Form1() {
11
            InitializeComponent();
12
        }
13
 
14
        private void ilPanel1_Load(object sender, EventArgs e) {
15
 
16
            // create random positions as circle midpoint locations
17
            Array<float> A = ILMath.tosingle(ILMath.randn(3, 150)) * 10;
18
            // the 4th dimension: here we take the distance from the middle of the distribution
19
            Array<float> V = ILMath.sqrt(ILMath.sum(ILMath.pow(A["0,1;:"] - ILMath.mean(A["0,1;:"], 1), 2f), 0));
20
 
21
            // create a colormap
22
            var cm = new Colormap(Colormaps.Hot);
23
            // configure min / max values (the full range for the colormap)
24
            float min, max;
25
            V.GetLimits(out min, out max);
26
            // map values to colors 
27
            Array<float> colors = cm.Map(V, Tuple.Create(min, max)).T;
28
            // add minimal setup: plotcube
29
            var pc = ilPanel1.Scene.Add(new PlotCube(twoDMode: false));
30
 
31
            // add individual circles, configure color based on colormap
32
            var size = new Vector3(0.1, 0.1, 1); 
33
            for (int i = 0; i < A.S[1]; i++) {
34
                var col = Color.FromArgb(255, (int)(255 * colors.GetValue(0, i)), (int)(255 * colors.GetValue(1, i)), (int)(255 * colors.GetValue(2, i)));
35
                var gr = pc.Add(new Group() {
36
                    Children = {
37
                        new Circle(20) {
38
                            Fill = { Color = col }
39
                        }
40
                    }
41
                });
42
                gr.Translate(A.GetValue(0, i), A.GetValue(1, i), A.GetValue(2, i)); // circles are placed in 3D! 
43
                gr.Scale(size); 
44
            }
45
 
46
            // add colorbar 
47
            pc.Add(new Colorbar() {
48
                ColormapProvider = new StaticColormapProvider(cm, min, max)
49
            });
50
 
51
            // add title 
52
            Text = "ILNumerics Visualization Engine - Colormapped Circles in Plot Cube"; 
53
        }
54
    }
55
}
 
 

TOP

All Examples

cm
1
n
 
 
We and our partners use technology such as cookies or pixels on our site to personalize content and ads, provide social media features, and analyze our traffic across devices and platforms. Tracking activities can be controlled or disabled. By continueing using our website you agree on the placement of related cookies and the use of data delivered by your browser for such purposes. Read more in our data privacy statement.
Got it!