Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / Visual C++ 10.0
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.20/5 (3 votes)
9 Apr 2018CPOL 36.9K   606   12   9
C++ header file to plot data in the form of x, y, z arrays and list as potential lines and graphs

Introduction

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.

Implementation

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

C++
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 is:

Image 1

Clear the temporary plot buffer by calling:

C++
SVG_clearPlotBuffer(); 

Plot potential lines:

C++
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:

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

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

To plot potential lines, call:

JavaScript
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 

XXYYZZArrays2SVGImage_potential_lines("test.svg",  
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:

Image 2

Point of Interest

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

History

  • Version 1.02

License

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


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Question[My vote of 1] Just a C-wrapper around some STL classes Pin
René Greiner15-Apr-18 2:50
René Greiner15-Apr-18 2:50 
AnswerRe: [My vote of 1] Just a C-wrapper around some STL classes Pin
gintack19-Apr-18 4:11
gintack19-Apr-18 4:11 
Questionusing namespace std; Pin
degski11-Apr-18 3:10
degski11-Apr-18 3:10 
AnswerRe: using namespace std; Pin
gintack19-Apr-18 4:06
gintack19-Apr-18 4:06 
QuestionBuild errors on Windows ( VS 2010 ) Pin
va_dev20-Apr-13 3:57
va_dev20-Apr-13 3:57 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack23-Apr-13 10:41
gintack23-Apr-13 10:41 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack28-Apr-13 2:36
gintack28-Apr-13 2:36 
GeneralRe: Build errors on Windows ( VS 2010 ) Pin
degski11-Apr-18 3:15
degski11-Apr-18 3:15 
AnswerRe: Build errors on Windows ( VS 2010 ) Pin
gintack19-Apr-18 4:04
gintack19-Apr-18 4: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.