PLC and PMC draw option in pyroot

Hi,
I’m trying the nice new feature of PLC and PMC draw options, but my below simple pyroot code does not work well:

#!/usr/bin/env python
from ROOT import *

h1 = TH1F("h1","h1",50,-10,10)
h2 = TH1F("h2","h2",50,-10,10)
h3 = TH1F("h3","h3",50,-10,10)
h4 = TH1F("h4","h4",50,-10,10)

h1.FillRandom('gaus',1500)
h2.FillRandom('gaus',1000)
h3.FillRandom('gaus',500)
h4.FillRandom('gaus',200)

h2.SetMarkerStyle(20)
h1.SetMarkerStyle(25)
h3.SetMarkerStyle(26)

opt='E'
h1.Draw(opt+'PLC PMC')
h2.Draw(opt+'SAME PLC PMC')
h3.Draw(opt+'SAME PLC PMC')
h4.Draw('SAME')

gPad.BuildLegend();
gPad.Update()

x = raw_input("wait:")

The styles change when the canvas is clicked. And, the 1st one and last one always have the same color?
Also, the histograms are not visible on the Canvas if I use opt=’’.

I’m not sure if this is due to my configuration. Any thing obviously wrong in this code? Thanks!

In principle it should work the same with C++ or python. I will try.

The working C++ version is:

{
   auto *c  = new TCanvas("c","c",800,600);
   auto *h1 = new TH1F("h1","h1",50,-10,10);
   auto *h2 = new TH1F("h2","h2",50,-10,10);
   auto *h3 = new TH1F("h3","h3",50,-10,10);
   auto *h4 = new TH1F("h4","h4",50,-10,10);

   h1->FillRandom("gaus",1500);
   h2->FillRandom("gaus",1000);
   h3->FillRandom("gaus",500);
   h4->FillRandom("gaus",200);

   h2->SetMarkerStyle(20);
   h1->SetMarkerStyle(25);
   h3->SetMarkerStyle(26);

   h1->Draw("E PLC PMC");
   h2->Draw("E SAME PLC PMC");
   h3->Draw("E SAME PLC PMC");
   h4->Draw("SAME");
   c->Update();

   c->BuildLegend();
   c->Update();
}

Thanks. I confirm that creating the TCanvas explicitly instead of using the auto-created one solves the problem.

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