Click here to Skip to main content
11,704,315 members (62,813 online)
Click here to Skip to main content

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

, 11 Apr 2013 CPOL 8.4K 204 4
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.

Introduction

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 www.schiso.com 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,
"TEST");

 // 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 

SVG_clearPlotBuffer(); 

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.

3;6;9
2;5;8
1;4;7

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); 
END 
END

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};  
XXYYZZArrays2SVGImage_potential_lines("test.svg",  
10 /* X DIM -> 10*10 */,
10 /* Y DIM -> 10*10 */,
XX,YY,ZZ, 
"NAME", 
"X-AXIX NAME", 
"Y-AXIS NAME", 
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.

History

This is the first version ever written and published, version 1.02.

License

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

Share

About the Author

gintack
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 3:57
memberva_dev20-Apr-13 3:57 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack23-Apr-13 10:41
membergintack23-Apr-13 10:41 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack28-Apr-13 2:36
membergintack28-Apr-13 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web03 | 2.8.150819.1 | Last Updated 11 Apr 2013
Article Copyright 2013 by gintack
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid