Unable to Retain the Style of the projection Histogram on using HBAR

Dear Experts,
I am trying to make a 2D plot and its 1D projections. Here’s the macrob2_style_pad.C (7.0 KB) and the root file for_fds_plots.root (177.2 KB) that i am using. The resulting plot that I get, is:unnamed.pdf (67.3 KB) I want the bottom right plot to have the same style as that of the top left plot and the 2D his to gram should look like: for_approval_2D_fds.pdf (124.8 KB) But, even after including all the required lines in the macro, I am not able to get the plots in the required style. It think it is some default settings which comes with hbar.

It will be really great if you helped me sort it out.

Gratefully,
Sanjeeda
_
Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Ubuntu
Compiler: Not Provided


Hi Sanjeeda,

You are trying to use “hbar” draw option to draw histogram with swapped axes.
As options says - it always draw bar for each bin, therefore you cannot get line out of that drawing.
To be able draw that you want, you have to create TGraph object and specify (x,y) points as you want.

Regards,
Sergey

Dear @linev,

Thank you for your answer, however, I am not sure I understand what you mean. Will you please show me how to do it

Hi,

I mean to create TGraph from histogram points like this:

TGraph *make_swapped_graph(TH1 *h1) {
   // copy all points from histogram
   TGraph *gr = new TGraph(h1);
   Int_t nbins = gr->GetN();
   Double_t x,y;
   // swap x/y coordinates
   for (int n=0;n<nbins;++n) {
      gr->GetPoint(n,x,y);
      gr->SetPoint(n,y,x);
   }
   return gr;
}

And then draw such graphs instead of histograms.
Here is complete macro - with few errors corrections: b2_style_pad.C (7.4 KB)

And produced image.

1 Like

Thanks a lot @linev, As I want the same style for both the projections, So I have used TGraph for the top left plot as well. Here’s the modified macro.b2_style_pad.C (8.4 KB) . However, there is another issue with the markers of the 2D histogram. I am aable to change the marker attributes (of the histogram that is dram in sames, h2) using the draw panel but I can’t do the same for the markers for h1. Would you please help me fix that too?. Here’s the current result.

Really grateful,
Sanjeeda

Where th1 histogram is drawn? I only see th2 and TGraph objects?

it is there in the code I have used a root file towards the upper part, below TGraph *make_swapped_graph1(TH1 *h2). h1 and h2 are drawh on the Center pad, line 206 in my code.

Could we make a Scatter plot instead of the 2D histogram because the 1D projections are now graphs?

You have two TH2 histograms, both drawn as scatter plot - default for TH2 histograms.
To change color and size of markers, you should do:

h1->SetMarkerColor(kBlue);
  h1->SetMarkerStyle(8);
  h1->SetMarkerSize(0.3);
  h1->Draw();
  h2->SetMarkerColor(kRed);
  h2->SetMarkerStyle(8);
  h2->SetMarkerSize(0.5);
  h2->Draw("same");
1 Like

Thanks a lot @linev. I was drawing it before setting the styles. Now every thing is just right.
You can’t imagine how relieved I am. :relieved:

Extremely grateful,

Sanjeeda