Commit fb43f50d authored by Martin Karlsson's avatar Martin Karlsson
Browse files

add gnuplot

parent 3247ca2d
This is a code example of modification of DMPs.
Requirements:
g++ compiler
Armadillo C++ Linear Algebra Library
http://arma.sourceforge.net/
Note: Before installing Armadillo, it's required to have LAPACK and BLAS installed, along with the corresponding development/header files.
CFLAGS = -ggdb
DEFINES = -DDEBUGGA
INCLUDES =
LIBS = -lstdc++
EXAMPLE = example.o
CC=g++
.cc.o:
$(CC) -c $(CFLAGS) $(DEFINES) $(INCLUDES) $<
all:: example
gnuplot_i.o: gnuplot_i.hpp
example.o: example.cc
example: $(EXAMPLE)
$(CC) -o $@ $(CFLAGS) $(EXAMPLE) $(LIBS)
clean:
rm -f $(EXAMPLE) example
# Doxyfile 1.5.6
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = gnuplot-cpp
PROJECT_NUMBER = 0.9
OUTPUT_DIRECTORY = ./
CREATE_SUBDIRS = YES
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = NO
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
SHOW_FILES = YES
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = ../
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS =
EXAMPLE_PATH = ../example.cc
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = YES
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
HTML_DYNAMIC_SECTIONS = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
CHM_INDEX_ENCODING =
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
FORMULA_FONTSIZE = 10
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_FONTNAME = FreeSans
DOT_FONTPATH =
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = YES
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO
// Example for C++ Interface to Gnuplot
// requirements:
// * gnuplot has to be installed (http://www.gnuplot.info/download.html)
// * for Windows: set Path-Variable for Gnuplot path (e.g. C:/program files/gnuplot/bin)
// or set Gnuplot path with: Gnuplot::set_GNUPlotPath(const std::string &path);
#include <iostream>
#include "gnuplot_i.hpp" //Gnuplot class handles POSIX-Pipe-communikation with Gnuplot
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
#include <conio.h> //for getch(), needed in wait_for_key()
#include <windows.h> //for Sleep()
void sleep(int i) { Sleep(i*1000); }
#endif
#define SLEEP_LGTH 2 // sleep time in seconds
#define NPOINTS 50 // length of array
void wait_for_key(); // Programm halts until keypress
using std::cout;
using std::endl;
int main(int argc, char* argv[])
{
// if path-variable for gnuplot is not set, do it with:
// Gnuplot::set_GNUPlotPath("C:/program files/gnuplot/bin/");
// set a special standard terminal for showonscreen (normally not needed),
// e.g. Mac users who want to use x11 instead of aqua terminal:
// Gnuplot::set_terminal_std("x11");
cout << "*** example of gnuplot control through C++ ***" << endl << endl;
//
// Using the GnuplotException class
//
try
{
Gnuplot g1("lines");
//
// Slopes
//
cout << "*** plotting slopes" << endl;
g1.set_title("Slopes\\nNew Line");
cout << "y = x" << endl;
g1.plot_slope(1.0,0.0,"y=x");
cout << "y = 2*x" << endl;
g1.plot_slope(2.0,0.0,"y=2x");
cout << "y = -x" << endl;
g1.plot_slope(-1.0,0.0,"y=-x");
g1.unset_title();
//
// Equations
//
g1.reset_plot();
cout << endl << endl << "*** various equations" << endl;
cout << "y = sin(x)" << endl;
g1.plot_equation("sin(x)","sine");
cout << "y = log(x)" << endl;
g1.plot_equation("log(x)","logarithm");
cout << "y = sin(x) * cos(2*x)" << endl;
g1.plot_equation("sin(x)*cos(2*x)","sine product");
//
// Styles
//
g1.reset_plot();
cout << endl << endl << "*** showing styles" << endl;
cout << "sine in points" << endl;
g1.set_pointsize(0.8).set_style("points");
g1.plot_equation("sin(x)","points");
cout << "sine in impulses" << endl;
g1.set_style("impulses");
g1.plot_equation("sin(x)","impulses");
cout << "sine in steps" << endl;
g1.set_style("steps");
g1.plot_equation("sin(x)","steps");
//
// Save to ps
//
g1.reset_all();
cout << endl << endl << "*** save to ps " << endl;
cout << "y = sin(x) saved to test_output.ps in working directory" << endl;
g1.savetops("test_output");
g1.set_style("lines").set_samples(300).set_xrange(0,5);
g1.plot_equation("sin(12*x)*exp(-x)").plot_equation("exp(-x)");
g1.showonscreen(); // window output
//
// User defined 1d, 2d and 3d point sets
//
std::vector<double> x, y, y2, dy, z;
for (int i = 0; i < NPOINTS; i++) // fill double arrays x, y, z
{
x.push_back((double)i); // x[i] = i
y.push_back((double)i * (double)i); // y[i] = i^2
z.push_back( x[i]*y[i] ); // z[i] = x[i]*y[i] = i^3
dy.push_back((double)i * (double)i / (double) 10); // dy[i] = i^2 / 10
}
y2.push_back(0.00); y2.push_back(0.78); y2.push_back(0.97); y2.push_back(0.43);
y2.push_back(-0.44); y2.push_back(-0.98); y2.push_back(-0.77); y2.push_back(0.02);
g1.reset_all();
cout << endl << endl << "*** user-defined lists of doubles" << endl;
g1.set_style("impulses").plot_x(y,"user-defined doubles");
g1.reset_plot();
cout << endl << endl << "*** user-defined lists of points (x,y)" << endl;
g1.set_grid();
g1.set_style("points").plot_xy(x,y,"user-defined points 2d");
g1.reset_plot();
cout << endl << endl << "*** user-defined lists of points (x,y,z)" << endl;
g1.unset_grid();
g1.plot_xyz(x,y,z,"user-defined points 3d");
wait_for_key();
g1.reset_plot();
cout << endl << endl << "*** user-defined lists of points (x,y,dy)" << endl;
g1.plot_xy_err(x,y,dy,"user-defined points 2d with errorbars");
//
// Multiple output screens
//
cout << endl << endl;
cout << "*** multiple output windows" << endl;
g1.reset_plot();
g1.set_style("lines");
cout << "window 1: sin(x)" << endl;
g1.set_grid().set_samples(600).set_xrange(0,300);
g1.plot_equation("sin(x)+sin(x*1.1)");
g1.set_xautoscale().replot();
Gnuplot g2;
cout << "window 2: user defined points" << endl;
g2.plot_x(y2,"points");
g2.set_smooth().plot_x(y2,"cspline");
g2.set_smooth("bezier").plot_x(y2,"bezier");
g2.unset_smooth();
Gnuplot g3("lines");
cout << "window 3: log(x)/x" << endl;
g3.set_grid();
g3.plot_equation("log(x)/x","log(x)/x");
Gnuplot g4("lines");
cout << "window 4: splot x*x+y*y" << endl;
g4.set_zrange(0,100);
g4.set_xlabel("x-axis").set_ylabel("y-axis").set_zlabel("z-axis");
g4.plot_equation3d("x*x+y*y");
Gnuplot g5("lines");
cout << "window 5: splot with hidden3d" << endl;
g5.set_isosamples(25).set_hidden3d();
g5.plot_equation3d("x*y*y");
Gnuplot g6("lines");
cout << "window 6: splot with contour" << endl;
g6.set_isosamples(60).set_contour();
g6.unset_surface().plot_equation3d("sin(x)*sin(y)+4");
g6.set_surface().replot();
Gnuplot g7("lines");
cout << "window 7: set_samples" << endl;
g7.set_xrange(-30,20).set_samples(40);
g7.plot_equation("besj0(x)*0.12e1").plot_equation("(x**besj0(x))-2.5");
g7.set_samples(400).replot();
Gnuplot g8("filledcurves");
cout << "window 8: filledcurves" << endl;
g8.set_legend("outside right top").set_xrange(-5,5);
g8.plot_equation("x*x").plot_equation("-x*x+4");
//
// Plot an image
//
Gnuplot g9;
cout << "window 9: plot_image" << endl;
const int iWidth = 255;
const int iHeight = 255;
g9.set_xrange(0,iWidth).set_yrange(0,iHeight).set_cbrange(0,255);
g9.cmd("set palette gray");
unsigned char ucPicBuf[iWidth*iHeight];
// generate a greyscale image
for(int iIndex = 0; iIndex < iHeight*iWidth; iIndex++)
{
ucPicBuf[iIndex] = iIndex%255;
}
g9.plot_image(ucPicBuf,iWidth,iHeight,"greyscale");
g9.set_pointsize(0.6).unset_legend().plot_slope(0.8,20);
//
// manual control
//
Gnuplot g10;
cout << "window 10: manual control" << endl;
g10.cmd("set samples 400").cmd("plot abs(x)/2"); // either with cmd()
g10 << "replot sqrt(x)" << "replot sqrt(-x)"; // or with <<
wait_for_key();
}
catch (GnuplotException ge)
{
cout << ge.what() << endl;
}
cout << endl << "*** end of gnuplot example" << endl;
return 0;
}
void wait_for_key ()
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) // every keypress registered, also arrow keys
cout << endl << "Press any key to continue..." << endl;
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
_getch();
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
cout << endl << "Press ENTER to continue..." << endl;
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin.get();
#endif
return;
}
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment