Hello experts,
I would like to plot a graph that updates after each step in a for-loop. The MWE is simple and looks like this
#include <iostream>
#include <thread>
#include <chrono>
#include "TApplication.h"
#include "TAxis.h"
#include "TCanvas.h"
#include "TGraph.h"
int main ( ) {
TApplication app("app",0,0);
TGraph * myGraph = new TGraph();
TCanvas *c = new TCanvas();
c->cd();
c->Update();
myGraph->GetXaxis()->SetTitle("Tempo [s]");
myGraph->GetYaxis()->SetTitle("Posizione x [m]");
double t = 0;
for (int step=0; step<100; step++) {
std::cout << "t " << t << std::endl;
myGraph->SetPoint(step,t,sin(t));
myGraph->Draw("AL*");
c->Modified();
c->Update();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
t = t+0.2;
}
app.Run();
return 0;
}
and it is compiled with
g++ -o main main.cxx `root-config --libs` `root-config --cflags`
This codes works on linux, the canvas is opened as soon as the main script is called, and each step of the sine function is displayed after the interval. On Mac (both on Intel and on M1) instead the canvas is opened only at the end, when the for-loop is done. Is there any additional commands to be included to make the application works properly on Mac? Thanks
Linux version
ROOT Version: 6.28/10
Platform: linuxx8664gcc
Compiler: g++ (GCC) 11.3.0
Mac M1
ROOT Version: 6.28/04
Platform: macosxarm64