Warm tip: This article is reproduced from stackoverflow.com, please click
c++ c++11 root-framework

Creating plot via TF1 library

发布于 2020-03-27 10:23:35

I want to create a plot with a TF1 function in my C++ program. For compiling I use

g++ *.cpp $(root-config --cflags --glibs)

and that works just fine.

But when I do ./a.out afterwars it just won't show me the canvas it created (it says in the shell that a canvas C1 was created).

I already tried using a dummy with cin >> dummy but that doesn't work either

Questioner
TwoStones
Viewed
113
Yury 2019-07-03 22:33

I created a tf1test.c with the following content:

#include <iostream>
#include <TCanvas.h>
#include <TApplication.h>

#include <TF1.h>

int main (int argc, char** argv)
{
        TApplication app("test", &argc, argv);
        TCanvas* c1 = new TCanvas("c1", "Something", 0, 0, 800, 600);

        TF1* myFunc = new TF1("myFunc", "2*sin(x)", 0, 10);
        myFunc->Draw();

        c1->Modified();
        c1->Update();

        Int_t a;
        printf("Press any key and hit 'Enter': ");
        std::cin>>a;

        return 0;
}

, now I'm compiling it with

g++ $(root-config --cflags --glibs) tf1test.c -o a.out

and launching with

./a.out

and both my canvas and TF1 show up.