Lumiera  0.pre.03
»edit your freedom«
gnuplot-gen.cpp File Reference

Go to the source code of this file.

Description

Definition of building blocks and preconfigured styles for Gnuplot scripts.

The purpose of this setup is to generate visualisations of measurement data easily. A collection of plotting definitions, together with uniform styles is maintained within this translation unit, exposing a simple interface where the user only needs to supply the actual data to be plotted. Intentionally, this collection is started without much structure or preconceptions and written in a way to encourage adding more use-cases by copy-and-paste. Following this pragmatic approach, generalisations and common schemes will emerge eventually.

Script generation

The resulting Gnuplot script is combined from several building blocks, and passed through the lib::TextTemplate engine to substitute the data and further configuration parameters at designated places into the code. Notably, the script performs further evaluations at run time, especially in reaction to the number of given data rows (relying on the stats command of Gnuplot). Data input is configured to CSV format and data is pasted as »here document« into a data block variable $RunData

simple plot
By default, the points plotting style is used; this can be overridden through the placeholder #KEY_DiagramKind. All given data rows are combined into a single plot, using a common x and y axis, and assigning consecutive line drawing styles to each data row (from blue to green, yellow, red). A maximum of 9 line styles is prepared for drawing. The x/y-ranges and custom labels can be added.
scatter plot with regression line
Typically this is used for measurement data, assuming linear relation. The data is visualised as (x,y) points, overlaying a linear regression line plotted in red. Possibly further data rows can be given, which are then plotted into a secondary diagram, arranged below the main measurement data and using the same x-axis layout. This additional display is featured only when more than 2 columns are present in the data; the number of columns is picked up from the second data row (since the first row provides the key names used for the legend). In further rows, some data points can be omitted. The 3rd data column will be shown as »impulse diagram«, while all further data columns will be displayed as points, using the secondary Y-axis. All axis ranges and labels can be customised. By default, the linear regression model is calculated by Gnuplot, based on the data in columns 1 and 2 (the main measurement data), yet an alternative regression line can be defined by parameters.
Todo:
WIP 4/2024 first usage as part of Scheduler stress testing.
See also
GnuplotGen_test

Definition in file gnuplot-gen.cpp.

#include "lib/text-template.hpp"
#include "lib/text-template-gen-node-binding.hpp"
#include "lib/gnuplot-gen.hpp"
#include "lib/format-util.hpp"
#include <string>

Functions

string dataPlot (ParamRecord)
 Generate a Gnuplot diagram to visualise the given data points. More...
 
string scatterRegression (ParamRecord)
 Generate a (X,Y)-scatter plot with regression line. More...
 

Variables

const string GNUPLOT_AxisGridSetup
 
const string GNUPLOT_BASIC_PLOT_DEF
 
const string GNUPLOT_CommonStyleDef
 
const string GNUPLOT_SCATTER_REGRESSION
 
const string GNUPLOT_SIMPLE_DATA_PLOT
 

Namespaces

 lib
 Implementation namespace for support and library code.
 

Function Documentation

◆ dataPlot()

string dataPlot ( ParamRecord  params)

Generate a Gnuplot diagram to visualise the given data points.

Remarks
each column of the given data is featured as sequence over the first column interpreted as common abscissa. The name of the abscissa and the row names in the legend are extracted from the header names expected in the first row of CSV data.

Definition at line 250 of file gnuplot-gen.cpp.

References lib::gnuplot_gen::dataPlot().

Referenced by lib::gnuplot_gen::dataPlot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scatterRegression()

string scatterRegression ( ParamRecord  params)

Generate a (X,Y)-scatter plot with regression line.

Remarks
the layout of this diagram differs, based on the given number of data columns. The main measurement data is expected in columns [1:2] and showed in the primary display, adding a regression line. When further columns are given, a multiplot layout is established, showing those additional related series in a second diagram below. It may be necessary to define a larger canvas with different aspect ratio, which is possibly using the placeholder #KEY_TermSize

Definition at line 274 of file gnuplot-gen.cpp.

References lib::gnuplot_gen::scatterRegression().

Referenced by lib::gnuplot_gen::scatterRegression().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: