Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) gnuplot example 1: creating and saving a plot

 

gnuplot example 1 is a gnuplot example.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppGnuplotExample1.pro

 

TEMPLATE = app
CONFIG += console
CONFIG += qt
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <fstream>
#include <string>
#include <cstdlib>

int main()
{
  #ifdef WIN32
  const std::string exe = "C:\\Progra~1\\gnuplot\\bin\\gnuplot.exe";
  #else
  const std::string exe = "gnuplot";
  #endif

  const std::string filename = "test.txt";
  {
    std::ofstream f(filename.c_str());

    f <<
      "set terminal pngcairo\n"
      "set output 'test.png'\n"
      "set key inside left top vertical Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n"
      "set samples 50, 50\n"
      "plot [-10:10] sin(x),atan(x),cos(atan(x))";
  }

  const std::string cmd = exe + " " + filename;

  std::system(cmd.c_str());


}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml