TTree::Draw -> how to change the default number of bins?

Hello :smiley:

I could not find how to set histogram number of bins while using TTree::Draw function.
By default it is 100. Is it possible to change it?

Thanks a lot,

See Users Guide and documentation of TTree::Draw

The binning information is taken from the environment variables


In addition, the name of the histogram can be followed by up to 9
numbers between ‘(’ and ‘)’, where the numbers describe the

1 - bins in x-direction
2 - lower limit in x-direction
3 - upper limit in x-direction
4-6 same for y-direction
7-9 same for z-direction

When a new binning is used the new value will become the default.
Values can be skipped.
// plot sqrt(x) between 10 and 20 using 500 bins
// plot sqrt(x) against sin(y)
// 100 bins in x-direction; lower limit on x-axis is 10; upper limit is 60
// 50 bins in y-direction; lower limit on y-axis is .1; upper limit is .5



how can I modify the default in PyROOT?

If I try Hist.Binning.2D.x = 1000 it says “wrong sintax”.
I could do it histogram by histogram with (nbins,xmim,xmax,…) but it would be nice just to have a new default. Also because I’d like to keep the minimum and maximum free (so that it will adapt to the distribution plotted).


Hi Lucas, Hist.Binning.2D.x is a variable in your .rootrc file, not a thing in C++. The standard rootrc file lives somewhere in your root/etc directory and it’s called system.rootrc. You have a user-specific .rootrc file at ~/.rootrc where you can override the system defaults.

Go read the system.rootrc file to look at the syntax. You can change the system-wide default there, or you can add an entry to your user-specific .rootrc file to override the system default.


Hi Jean-François,

Thanks for the very quick answer.
I’ve make a .rootrc and I’ve modified the number of bins.
If I open root and type gEnv->Print() I see that my modification works OK.
But when I run my python script it still has the original number of bins.
Do I need to load the .rootrc in some special way?


That’s strange. The settings that I override in my user-specific .rootrc are shown properly in PyROOT with ROOT.gEnv.Print(), and in ROOT with gEnv->Print().

Maybe ask again in the PyROOT forum?


Hi everyone,

I want to thank you for your help.
I solved it. I was stupidly writing

Hist.Binning.1D.x = 100

instead of

Hist.Binning.1D.x: 100