An unwanted horizontal line is drawn at y=0

When I draw a THStack, a horizontal line y=0 is also drawn. How to remove this line? Thanks.

void fill_tree(const char *treeName, const char *fileName)
  ROOT::RDataFrame d(25000);
  d.Define("px", []() { return gRandom->Gaus(); })
    .Define("py", []() { return gRandom->Gaus(); })
    .Define("pz", [](double px, double py) { return sqrt(px * px + py * py); }, {"px", "py"})
    .Snapshot(treeName, fileName);

void df003_profiles()
  auto fileName = "df003_profiles.root";
  auto treeName = "myTree";
  fill_tree(treeName, fileName);

  ROOT::RDataFrame d(treeName, fileName, {"px", "py", "pz"});

  auto hprofyx = d.Profile1D({"hprofyx", "Profile of py versus px", 64, -4, 4}, "py", "px");
  auto hprofzx = d.Profile1D({"hprofzx", "Profile of pz versus px", 64, -4, 4}, "pz", "px");

  auto hs = new THStack("hs",";px; py and pz");

  auto c1 = new TCanvas("c1", "Profile histogram example");
  hs->Draw("nostack hist C PLC");

  auto fout = TFile::Open("profiles.root","recreate");

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.26/02
Platform: CentOS 7
Compiler: GCC 9.3.0

Can you save hprofyx and hprofzx in a ROOT file and send them, so I can try?

Dear @couet ,
I saved them in this ROOT file. Thanks a lot!
profiles.root (6.4 KB)

   TFile *f = TFile::Open("profiles.root");
   TProfile *hprofyx = (TProfile*)f->Get("hprofyx");
   TProfile *hprofzx = (TProfile*)f->Get("hprofzx");
   auto hs = new THStack();
   auto c = new TCanvas();
   hs->Draw("same nostack hist l plc");

Is there anything wrong in my original maco?

No, By default an horizontal line at 0 is drawn when a 1D histogram has negative content. The macro I sent you is the way to bypass this.

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