Improving pixel in 2D plots

Dear everyone,
I am struggling to improve a 2 D plot I made in order to see better the colors and points…by changing the draw option or something like that but have some troubles to do it.
For instance here is my code that generate the plot:

 TFile* f0   = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/E12cmfoMtotVsDeltaM_200_GeV.root");
   TH1F* Hist_E12VsM12_200_GeV   = (TH1F*)f0->Get("myHist_E12cmfoMtotvsDeltaM_all");
 Double_t scale1 = 1/Hist_E12VsM12_200_GeV->Integral();
    Hist_E12VsM12_200_GeV->Scale(scale1);
  
   TFile* f1  = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/E12cmfoMtotVsDeltaM_400_GeV.root");
   TH1F * Hist_E12VsM12_400_GeV   = (TH1F*)f1->Get("myHist_E12cmfoMtotvsDeltaM_all");
Double_t scale2 = 1/Hist_E12VsM12_400_GeV->Integral();
    Hist_E12VsM12_400_GeV->Scale(scale2);
 TFile* f2  = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/E12cmfoMtotVsDeltaM_600_GeV.root");
   TH1F * Hist_E12VsM12_600_GeV   = (TH1F*)f2->Get("myHist_E12cmfoMtotvsDeltaM_all");
Double_t scale3 = 1/Hist_E12VsM12_600_GeV->Integral();
Hist_E12VsM12_600_GeV->Scale(scale3);
 TFile* f3  = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/E12cmfoMtotVsDeltaM_800_GeV.root");
 TH1F * Hist_E12VsM12_800_GeV   = (TH1F*)f3->Get("myHist_E12cmfoMtotvsDeltaM_all");
Double_t scale4 = 1/Hist_E12VsM12_800_GeV->Integral();
Hist_E12VsM12_800_GeV->Scale(scale4);


//gStyle->SetPalette(kBird);
    Hist_E12VsM12_800_GeV->SetTitle("");
    Hist_E12VsM12_800_GeV->GetXaxis()->SetTitle("#Deltam");
    Hist_E12VsM12_800_GeV->GetYaxis()->SetTitle("E12/M_{tot}");
    Hist_E12VsM12_200_GeV->SetFillColor(1);
    Hist_E12VsM12_400_GeV->SetFillColor(2);
    Hist_E12VsM12_600_GeV->SetFillColor(3);
    Hist_E12VsM12_800_GeV->SetFillColor(4);
    Hist_E12VsM12_800_GeV->Draw("box");
    Hist_E12VsM12_400_GeV->Draw("box same");
    Hist_E12VsM12_600_GeV->Draw("box same");
    Hist_E12VsM12_200_GeV->Draw("box same");

And I attached also the plot.
I would appreciate if someone could help.
Cheers

I see you are using the box option but your histograms are TH1F … box is an option for 2D histograms. Simply try the default option … The doc about histograms’ plotting options is here:
https://root.cern/doc/master/classTHistPainter.html

Hi thanks for replying,
In fact when I try the default option for instance by doing:

 Hist_E12VsM12_200_GeV->SetFillColor(1);
    Hist_E12VsM12_400_GeV->SetFillColor(2);
    Hist_E12VsM12_600_GeV->SetFillColor(3);
    Hist_E12VsM12_800_GeV->SetFillColor(4);
    Hist_E12VsM12_800_GeV->Draw("");
    Hist_E12VsM12_400_GeV->Draw("same");
    Hist_E12VsM12_600_GeV->Draw("same");
    Hist_E12VsM12_200_GeV->Draw("same");

it doesn’t take in account the colors instead all the histograms become black.
Cheers

Use SetLineColor instead of SetFillColor

Hi,
I tried SetLineColor, but I got the same.
Cheers

It works for me with this example:

{
   TH1F *h1 = new TH1F("h1","A red histogram",100,-4.,4.);
   h1->FillRandom("gaus", 50000);
   h1->SetLineColor(kRed);
   h1->Draw();

   TH1F *h2 = new TH1F("h2","A green histogram",100,-2.,2.);
   h2->FillRandom("gaus", 10000);
   h2->SetLineColor(kGreen);
   h2->Draw("same");
}

Hi,
I am not an expert in root so may be I am wrong, but it seems that for 1 D histogram like your exemple this is not a problem, it works but with 2D histogram it doesn’t take into account the color even when I try prof option.
I can send the entire code may be there is something that caused that but I don’t think so.
Cheers

But in the example you posted at the beginning, all your histograms are TH1F …
Can you post one of your root file containing one of the histogram you plot ? or put in your public on afs…

Hi,
I think I guess what was the problem. In fact since my histograms are 2D instead of using for instance this:

   TH1F* Hist_E12VsM12_200_GeV   = (TH1F*)f0->Get("myHist_E12cmfoMtotvsDeltaM_all");

I used this:

TH2D* Hist_E12VsM12_200_GeV   = (TH2D*)f0->Get("myHist_E12cmfoMtotvsDeltaM_all");

so just replacing TH1F by TH2D and as well SetFillColor by SetLineColor, and I use box option.
For instance I have this beautiful plot now.


Thanks a lot I found it thanks our discussion.
Could you just explain me something for my understanding? why it doesn’t take in account colors when using the default option even when I did the change by replacing TH1F by TH2D.
Cheers

I am not completely sure of what you are/were doing as I saw only partially your code. I guess you had mismatches between the type of histogram, the option you choose and the colour attribute you used… Good you found the solution.

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