Histogram. Custom grid

Hello,

I would like to plot grid lines at custom points (no equally spaced). Is it possible? I tried with TLines, but there is a problem when you zoom in.

Thank you for your time.

Regards,
atd


ROOT Version: ROOT 6.10/08
Platform: CC7
Compiler: gcc 4.8.5


Yes TLine is the way. Can you post a reproducer showing what you are doing ?

Hello,

A working example,

TH2D h("h","",10,0,10,10,0,10); 
h.Draw(); 
TLine aline(0,5,10,5); 
aline.Draw();
// looks  ok, but if we zoom in...
h.GetXaxis()->SetRangeUser(2,8);

After zooming in, the line stands out the histogram. I would like to have something like the grid lines, so when you zoom in, the grid lines don’t stand out the histogram axis.

Thank you for your time.

Regards,
Alvaro

customgrid.C (354 Bytes)

1 Like

Thanks a lot, it was what I was looking for!

Just out of curiosity, why “TExec” is needed?

Regards,
atd

TExec is an object placed in the TCanvas display list. It executes the script passed in argument each time the canvas is painted. When you zoom the canvas it is automatically repainted with different values along the X axis therefore if you paint a line with fixed values, they do not take into account the new axis limits defined by the zoom. Putting the line painting into a TExec allows to recompute correctly the line position each time the canvas is painted. TExec encapsulates the line painting with some code allowing to recompute the line position each time the canvas is painted.

1 Like

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