Click here to Skip to main content
12,702,596 members (32,940 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked

C++ header to plot vector<float> and arrays to SVG. Function and potential line plots

, 11 Apr 2013 CPOL
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.


Its an undocumented C++ file to plot potential lines and graphs as a SVG file from arrays and point vectors in C++.   The name of the x and y axis need to be rearranged, after the plot is created.

Feel free to use the file and to add what ever you may need it to do, you could get in touch with me and write me to my business e-mail, if you have questions.  

Using the code

To plot a list<VAR> with a function name as SVG graphic, 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 would be (I changed the position of the x and y axis titles and deleted the name of the graph):

You can always clear the plot buffer by calling 


Example for plotting 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 distant to each other.


The above is a 3x3 Grid with 9 points and their index and position.

The orientation of the points in the buffer is A MUST. Here is an example:

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 XX[x+y*DIM(x)] = f(x,y); 

So point 1 would map: 

x ->

To plot the potential lines use

VAR pos[10] = {0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,0.01,0.02};  
10 /* X DIM -> 10*10 */,
10 /* Y DIM -> 10*10 */,
10 /* number of lines to show */, 
pos /* 10 values from 0-1 -> label position relative to the potential line path. 
   The value can also be set to NULL to plot no value labels  ... */);

An example file of the above code is below (I changed the positions of the axis titles and the name of the plot).

Point of Interest

I wrote the code to create plots.


This is the first version ever written and published, 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

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 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 11 Apr 2013
Article Copyright 2013 by gintack
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid