Adding a grid to a plot

I usually use TGaprh/TMultiGraph to make some plots, and i want to add a grid to some of them.
My requirements are:

  1. Being able to determine the distane between grid lines.

  2. Grid lines must appear in the front of the image.

  3. Must have lines and not dots.

I already asked about this here but the solution i was offered is not good because SetNdivisions is limited to 100 grid lines (my range is about -15,000 to 15000 units and i want a grid line every 5 units).
I am new to ROOT and this is a bit confusing.

For example, this is one of my files -

It is visible that there are dots and not lines, they are behind the image and not in the front, and the spaces are too large.

After you draw your TGraph/TMultiGraph, try to execute:
gPad->RedrawAxis(“g”);

What is “g”? it seems to have no effect.

The following is stated in the documentation that was linked:

You should have continued with the previous thread instead of opening a new one. Any way if you need more than 99 divisions it is clear that the number of divisions parameter will not allow to define that.

Note that the plot you are showing has much less than 100 divisions … also if you are drawing that many divisions I am afraid the plot will be completely unreadable unless you produce a large output.

I think you need some custom way of drying the grid line by line. Do you have any example or plot showing exactly what you need ? the macro i posted in the other thread was just a example. You did not says you need 100 grid lines.

Finally you said:

The macro I sent you before fulfil completely these requirements.

1 Like
  1. Sorry about the new post, the first one was closed. My demands are also more clear to me right now.

  2. The plot i showed has less than a 100 divisions because, as you said it is not possible.

  3. i don’t mind producing a large output, but even a smaller size would require more than a 100 divisions.

  4. when I run youre macro with the the root terminal it seems to work, but this make the rest of my code crash. When I compile it with g++ I get the above plot.

  5. This image was produced with matplotlib, i would like something similar in ROOT:

ofirar2.C (1.4 KB)

1 Like

Thanks! this looks very good. inly one issue - i can only print either the grid or my TMultiGraph. what could cause this?

Can you post the macro having problems ?

Try printing the graph with a flag “ALPF” (this is the one im using). it makes the grid dissappear.

You should use the option P only … read the manual and you will understand that `A’ redefines the axis … therefore the grid drawn before is erased …

L ? … why? it seems you want only point …
F ? … idem

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