TH2 with arbitrary bin shape

Thank you for the example! In interactive mode it works fine.
I should have mentioned that I need this in c++ compiled mode.

My compilation command is

g++ lego.cpp -o Lego -pthread -std=c++11 -m64 -msse4.2 -I/localhome/myUser/Software/ROOT/root/include -L/localhome/myUser/Software/ROOT/root/lib -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic -L/localhome/myUser/Software/ROOT/root/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic -I/localhome/myUser/Software/ROOT/root/include -lRGL

My (minimal) NOT working example is

#include <stdlib.h>
#include <TROOT.h>
#include <TCanvas.h>
#include <TRandom3.h>
#include <TH2Poly.h>
#include <TStyle.h>

int main() {
  gStyle->SetCanvasPreferGL(true);
  TCanvas *canv = new TCanvas();
  TH2Poly *hc = new TH2Poly();
  hc->Honeycomb(0,0,.1,25,25);
  TRandom3 ran;
  for (int i = 0; i<300; i++) hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1));
  hc->Draw("GLLEGO ");
  canv->Print("LEGO.png");      
}

The .png file is completely blank.

Thanks in advance for further support!

Hi,
can you try switching Print with SaveAs?

Cheers,
Enrico

Doesn’t change nothing. Thanks for your commitment.
I think it has to do with openGL libraries.

Cheers
Dima

Uhm…maybe @couet knows then :sweat_smile:

(indeed I also get a blank canvas with the GL option, and the correct plot if I just use “LEGO”, no “GL”)

OpenGL works in interactive mode only. There is no batch mode. The png is created from the image rendered on screen.

Thanks. I’ll write the histogram to file then and call a ROOT script using the system() command to draw the histogram. Not very nice, but should work :wink: