0

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

TwoStones
  • 113
  • 5
  • did you check the comments under https://stackoverflow.com/a/56797361/4588453, especially the link to https://stackoverflow.com/a/36341590/4588453 ? – pseyfert Jul 02 '19 at 10:48
  • Possible duplicate of [Painting a TCanvas to the screen in a compiled ROOT (CERN) application](https://stackoverflow.com/questions/30932725/painting-a-tcanvas-to-the-screen-in-a-compiled-root-cern-application) – pseyfert Jul 02 '19 at 11:03

1 Answers1

0

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.

Yury
  • 423
  • 2
  • 7