Plotting with c# and .NET: Line Plots by ILNumerics
Line plots are used to visualize data in 1, 2 or 3 dimensions. Data points are connected by straight lines. Learn more about Line Plots in C#, Visual Basic and .NET:
In order to demonstrate the capabilities of ILNumerics for creating plots in C#, VB and .NET, we created some random data vector and provide it to a new LinePlot object. The Line Plot is than added to the plotting cube: Since we did only provide 1-dimensional data to the plot cube, the values are interpreted as Y values and the X values are automatically created.
X-Y plots are generated by simply providing a matrix with two rows: X values in the first row, Y values in the second row:
The scheme applies similarly to 3D Line Plots, which expects 3 rows for X, Y and Z-coordinates.
Handling NaN Values
Line Plots are able to handle NaN values. Those points, which have a coordinate component of NaN (Not a Number) are simply omited from rendering. One may utilize this property for non-continous lines and to realize several lines by using a single LinePlot object.
Auto-Coloring Line Plots
If no color was specified in the constructor, the color for each line is set automatically. Every subsequent new Line Plot receives an individual color.
In the next example, 64 Line Plots are created. The Line Plots get automatically colored by the keyframes in the Lines colormap, which is displayed eventually in the result:
Line Plots: Customizing Line Properties
Line Plots expose the LinePlot.Line property. Lines are made out of line strips (LineStrip) and provide the following options for configuration:
- Color
- DashStyle
- Width
The next example creates a whole bunch of Line Plots, all with different style combinations. We use a more efficient method than creating every line plot separately. LinePlot provides the static method LinePlot.CreateXPlots() for creating a number of regular Line Plots from the rows of a matrix. It allows the definition of style parameter collections for color, style and width of every line:
If any property of the line needs to get changed after creation, the LinePlot.Line property provides access to the line strip object for full configuration. If the need arises, the configuration may even include the modification of any vertex buffer of the line strip object. That way fully dynamic plots can be realized.
Markers
Line Plots allow the definition of markers for their data points. Markers can be configured either in the contructor of LinePlot …
Or, alternatively, the LinePlot.Marker property allows the (re-)configuration of markers:
All existing predefined marker shapes are displayed by the following code:
Customizing Markers
Markers can be arbitrarily customized. They allow the addition of custom shapes. LinePlot.Marker is a group node, which serves as a template for all markers to be drawn. All shapes added to the LinePlot.Marker group will be repeatedly displayed for every data point.
In the next example, the marker from the example above will be extended by a crosshair, which is made of two simple red lines, added to the marker node:
Coordinate System for Markers
A marker is a group node, which defines its own coordinate system. The node transforms vertex positions of its child shapes from the XY range [-1…1] to the pixel size defined by LinePlot.Marker.Size. If the Size property is set to 9 (default) this means, objects which range from -1 to 1 in X or Y will have a length of 9 pixels in X or Y direction, centered at the position of the data point.
Marker Billboarding
Markers are always oriented towards the camera. Even for 3D plots, with arbitrary rotation applied, the X-Y plane of a marker will always face the camera. The Z-coordinate of the vertices of marker shapes can be used to define the order of markers in Z-directions.
Line Plots in C# and VB (.NET): Further readings
The ILNumerics plotting library allows you to create fully customizable 2d and 3d line plots using C# code. Learn more about axis configurations and logarithmic axes in ILNumerics: