Draw Y-axis histograms (hbar option not satisfying)


ROOT Version: 6.08.06-c8fb4
Platform: lxplus machines
Compiler: x86_64-slc6-gcc62-opt


Dear ROOT experts,
I would like to simply draw 2 histograms as following :
h_27[0].Draw()
h_27[1].Draw(“same”)
BUT in the Y-axis. 1 histogram is red filled and the other is only a dashed-line appearance to be visible on top of the other as shown by the plot1 here :
summaryDisco_onlyHELHC_15_X.pdf (14.6 KB)

After some googling, I have found the “hbar” option and it is not keeping the dashed line… see the plot2:
summaryDisco_onlyHELHC_15_Y.pdf (14.5 KB)

h_27[0].Draw(“hbar”)
h_27[1].Draw(“hbarsame”)

How can I do plot1 in Y-axis?
Bets regards, David.

I’m not sure if this is what you want:

bar
bar same

All plotting options can always be found in THistPainter

No it is not doing what I want. I don’t want ot have hbar style in the x axis.
What I want is to keep the style of plot1 and the histograms to be horizontal and not vertical.
So in summary plot1 with a flip of X-Y axis.

The line style has nothing to do with the bar or bar option. In your first plot you every likely have somewhere (in your macro) something like h->SetLineStyle(…).

Yes you are right. I have asked explicitely the style with SetLineStye(2).
What I have seen is that bar or hbar option are making hisotgrams filled by default and destroys the dash-line/not-filled style of my histogram.

My initial question is : how can I have my plot1 with horizontal histograms with this exact same style?

Ah yes… you are right the HBAR is always drawn as filled area never as lines. So you cannot make dashed line with hbar option.

any idea how to simply switch x and y axis ?

If you want a plot like the bar one you showed tI do not see any other way. May be you can try to show it without dotted line. using transparency for instance ?
or:
TGraph would allow to switch axis more easily than TH1. You can try to put your dotted line in a TGraph.

Can you explain me how to do the TGraph with x-y axis switched please?
Or give link to examples?

Instead of doing:

TGraph(n,x,y)

you do

TGraph(n,y,x)

OK it is very simple :slight_smile:
Thanks.

The possibility to change the line style with options Bar and HBAR is now implemented.

{
   TCanvas *c1 = new TCanvas("c1", "c1",10,45,700,502);
   c1->Divide(2,1);

   TH1F *hpx = new TH1F("hpx","This is the px distribution",10,-4,4);
   hpx->SetBinContent(0,1);
   hpx->SetBinContent(1,1);
   hpx->SetBinContent(2,1);
   hpx->SetBinContent(3,1);
   hpx->SetBinContent(4,1);
   hpx->SetBinContent(6,1);
   hpx->SetBinContent(7,2);
   hpx->SetBinContent(8,4);
   hpx->SetBinContent(9,4);
   hpx->SetBinContent(10,5);

   hpx->SetBarWidth(0.5);

   hpx->SetFillStyle(0);
   hpx->SetLineColor(kRed);
   hpx->SetLineStyle(kDashed);

   c1->cd(1); hpx->Draw("HBAR");
   c1->cd(2); hpx->Draw("BAR");
}

many thanks. I just got a try and I am not able to have what you are showing.
Do I have to use a specific ROOT version?

Oh, it is in the root master … the latest head version of root. i just did the commit.

Last question how to setup the latest head version of ROOT from lxplus?

I guess you will need to install ROOT yourself… As explained here https://github.com/root-project/root

(scroll down the page).

Thanks. I ll have a try.

It works. Many thanks.
Do you know when the new ROOT tag containing this update will be available? And which tag number will it be?

It is now in master only. So it will be in the next release. 6.18. we just release 6.16.

OK thanks a lot for your help.
Topic closed.