Try to BuildLegend in the GUI (freezes for eternity after pressing OK)
Try to uncomment canvas.BuildLegend() (freezes for eternity)
Change .Range(100000) to .Range(100) (now it takes ~10 sec for Legend to appear after pressing BuildLegend in GUI or code to finish if BuildLegend() inside the code)
@couet There seems to be a bug in drawing the legend, which is visible due to another bug in its creation.
The line: canvas.BuildLegend()
(quickly / immediately) creates a buggy (note X1=X2 and Y1=Y2): OBJ: TLegend TPave X1= 0.300000 Y1=0.210000 X2=0.300000 Y2=0.210000
and then the actual drawing triggered by canvas.Update() hangs forever.
@FoxWise A fix: canvas.BuildLegend(0.5, 0.2, 0.8, 0.5)
If x1 is equal to x2 and y1 is equal to y2 the legend will be automatically placed to avoid overlapping with the existing primitives already displayed. x1 is considered as the width of the legend and y1 the height. By default the legend is automatically placed with width = x1= x2= 0.3 and height = y1= y2 = 0.21.
… We are in that case.
This mechanism is working See legendautoplacedhere. Could it be a Python issue ? have you tried your example in C++ ?
int test(){
auto canvas = new TCanvas("test");
ROOT::RDataFrame df("pTrackAtCalo_lengthTrackCalo_Frank_0.0", "./final_roots/pTrackAtCalo_lengthTrackCalo_Frank_0.0.root");
//~1 minute executing time
auto gr = df.Filter("abs(PDG) == 321").Range(100).Graph("mom", "beta");
// freeze
// auto gr = df.Filter("abs(PDG) == 321").Range(100000).Graph("mom", "beta");
gr->Draw("AP");
gr->GetXaxis()->SetRangeUser(1., 10.);
gr->GetYaxis()->SetRangeUser(0.7, 1.1);
cout<<"Starting building the legend"<<endl;
canvas->BuildLegend();
gr->SetTitle("test_tree");
cout<<"Starting to Update the canvas"<<endl;
canvas->Update();
cout<<"I am working!"<<endl;
return 0;
}
Warning Warning in <TLegend::Paint>: Legend too large to be automatically placed; a default position is used
showed in the output.
While you’re at it … have also a look at this … in the “legendautoplaced” macro I used “c4->BuildLegend()->Print();” and the output was:
(...)
TLegendEntry: Object hpx Label This is the hpx distribution Option lpf <- 1 x lpf
TLegendEntry: Object h1 Label A green histogram Option lpflpf <- 2 x lpf
TLegendEntry: Object Label This is a TGraph Option lpflpflpf <- 3 x lpf
BTW. You’re right … also in a C++ code, the correct legend coordinates appear only after the canvas has been “physically updated”.
I am debugging. I will let you know.
Meanwhile do not use automatic placement.
BTW I saw your plot and there is no space inside the frame to place a legend without overlapping the plot.
Understood: The TGraphs you have in your plot have 64035 points each. Only scanning the first
one, to check if the legend “collide” it or not, takes ages. I will need to improve the algorithm in order to not check all the points but may be just a few in the graphs. So, yes, right now do not use the automatic placement.