gPad Update with TGraph2D not draw points

I want update a TGraph2D every time I add point to simulate a trajectory.
The following code update the canvas and axis but not the point.
If I remove Update() and ProcessEvents(), the macro draw correctly all points at the same time. I tried with and without ProcessEvents() but nothing works.
Thanks.

Macro.C

{
  auto c = new TCanvas ("c","", 1000, 1000 ,1000 ,1000);

  auto gr = new TGraph2D();
  gr->SetMarkerStyle(20);
  gr->Draw("P");
  
  for(int i=0; i<30; i++){
    gr->SetPoint(gr->GetN(), i+1, i-1, 1);
    gPad->Modified();
    gPad->Update();
    gSystem->ProcessEvents();
  }
  
  gr->Print();
}

_ROOT Version: 6.28/06
_Platform: Ubuntu 22.04
_Compiler: g++ v11.4.0


Hi,

Yes, I can reproduce the problem.
Reason is that painter is not updated when TGraph2D get new points.
There is simple workaround for now - just add gr->SetMargin(0); after gr->SetPoint(...).
This force recreation of histogram and all objects painters.

And I will try to provide fix that TGraph2D painter will work properly.

Regards,
Sergey

1 Like

Thanks very much, problem solved

Meanwhile PR Update TGraph2D properties before painting by linev · Pull Request #13919 · root-project/root · GitHub applied to fix original problem.
Same patch also included in 6.30 release - which will appear soon

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.