Click here to Skip to main content
13,864,078 members
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 10 Apr 2013
Licenced CPOL

C++ Header to Plot vector<float> as 2D Graphs and Arrays as Potential Line Maps to SVG Files

, 9 Apr 2018
Rate this:
Please Sign up or sign in to vote.
C++ header file to plot data in the form of x, y, z arrays and list as potential lines and graphs


An undocumented C++ file to plot potential lines and 2D graphs as SVG files. The input format for 2D graphs is a vector. The input format for a potential line maps are XX[], YY[] and ZZ[] = f(XX[i], YY[i]).

I wrote the code to plot aerospace simulation results and other simulation results in half a day to speed up productivity and automate the documentation process.

The name of the x and y axis have to be rearranged, as they are simply being dropped somewhere onto the plot.


To plot a vector<VAR> as graph, use the example below:

SVG_clearPlotBuffer();  // clear the SVG temporary buffer

list<VAR> function;

function.push_back(0); // x 1
function.push_back(2); // y 1
function.push_back(4); // x 2
function.push_back(4); // y 2

// adds a list of points X,Y,X,Y ... with a function name to the SVG temporary buffer
SVG_appendPointListBufferAS2DPlot( function,

 // writes the temporary SVG buffer to an SVG file with NAME, X-Axis name, Y-Axis title.
writeSVGPointListBufferAS2DPlot("test.svg", 0,0,0,
     "Rubber Materials", "Elongation", "Stress [Pa]");

The output of the above code is:

Clear the temporary plot buffer by calling:


Plot potential lines:

VAR  XX[100]; //- X coordinates of 100 points
VAR  YY[100]; //- Y coordinates of 100 points
VAR  ZZ[100]; //  - Values of 100 points

Make sure the points have an equal distance to each other and that the indexes are arranged as followed:


Pseudo code to create valid input buffers:

for x to DIM x do
for y to DIM y do 
SET XX[x+y*DIM(x)] = x;
SET YY[x+y*DIM(x)] = y;  
SET ZZ[x+y*DIM(x)] = f(x,y); 

To plot potential lines, call:

VAR pos[10] = {0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.01,0.02};  // plot 10 valued labels 
                                                       // onto corresponding potential line positions 

10 /* X DIM -> 10*10 */,
10 /* Y DIM -> 10*10 */,
XX,YY,ZZ, // input
"NAME",  /// name of the plot
"X-AXIX NAME",  /// x axis name
"Y-AXIS NAME",  /// y axis name
10 /* number of lines to show */, 
pos /* Add 10 valued labels onto the corresponding potential lines position (0..1; begin ... end). 
   The value can also be set to NULL to plot no value labels  ... */);

An example results in:

Point of Interest

I wrote the code to create plots and speed up productivity.


  • Version 1.02


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

Question[My vote of 1] Just a C-wrapper around some STL classes Pin
René Greiner15-Apr-18 3:50
memberRené Greiner15-Apr-18 3:50 
AnswerRe: [My vote of 1] Just a C-wrapper around some STL classes Pin
gintack19-Apr-18 5:11
membergintack19-Apr-18 5:11 
Questionusing namespace std; Pin
degski11-Apr-18 4:10
memberdegski11-Apr-18 4:10 
AnswerRe: using namespace std; Pin
gintack19-Apr-18 5:06
membergintack19-Apr-18 5:06 
QuestionBuild errors on Windows ( VS 2010 ) Pin
va_dev20-Apr-13 4:57
memberva_dev20-Apr-13 4:57 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack23-Apr-13 11:41
membergintack23-Apr-13 11:41 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack28-Apr-13 3:36
membergintack28-Apr-13 3:36 
GeneralRe: Build errors on Windows ( VS 2010 ) Pin
degski11-Apr-18 4:15
memberdegski11-Apr-18 4:15 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack19-Apr-18 5:04
membergintack19-Apr-18 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190214.1 | Last Updated 9 Apr 2018
Article Copyright 2013 by gintack
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid