Y-axis visibility

i was trying to plot this function with varying q:

Ok, first of all you should get rid of the segmentation violation:
I’m 99% sure that it is cause by these three lines:

f1->SetTitle("Incident Beam Energy; Differential Cross Section");
f2->SetTitle("Incident Beam Energy; Differential Cross Section");
f3->SetTitle("Incident Beam Energy; Differential Cross Section");

The SetTitle function expects either a string of the format “tttt” with only the title of the function or “tttt;xxxx;yyyy” withthe title of the function and the title of the x and y axes. Your string is missing a semicolon for this definition which is probably the reason for the segmantation violation (char array index out of bounds, Why has C++ so useless error messages? :smiley:)

It seems to me that you only wanted to set the x and y axes titles. This can be achieved this way:

f1->SetTitle(";Incident Beam Energy;Differential Cross Section");
f2->SetTitle(";Incident Beam Energy;Differential Cross Section");
f3->SetTitle(";Incident Beam Energy;Differential Cross Section");

Also see here:
https://root.cern.ch/doc/v614/classTF1.html#a3f80b00e53e6d0c262da34c254203f52

Afterwards your functions should be drawn with the gPad->SetLogy();s commented out. To fix these you should provide proper y ranges for logarhytmic sclale: Since exp(x) = 0 is either undefined or only valid for x = -inf your y-axis range must not include 0, otherwise the function cannot be drawn. I assume your function become negative at some point which is why root automatically choses a y-axis range that includes 0 which leads to the error.
You can fix this by setting the extremes manually:

f1->SetMinimum(1.e-5);
f1->SetMaximum(1.e2);
f2->SetMinimum(1.e-5);
f2->SetMaximum(1.e2);
f3->SetMinimum(1.e-5);
f3->SetMaximum(1.e2);

Of course you should adjust the values to reasonable ones (I don’t know your functions). After this the logarhytmic sclae should also work.

Try with “23.0, 100.0” (instead of “0.0, 10.0”).

Note: You must make sure that you define a proper domain of your function (i.e. the denominator in your function must not be zero and the argument of the sqrt must not be negative).

BTW. @Triple_S ROOT is protected against empty / non-existent / misformed titles (or parts of them) so, you should not get any crashes. Also, in the majority of cases, it can automatically deal with non-positive values when asked for a log scale (unless you explicitly SetMinimum to be less or equal 0 or if all values are non-positive). Unfortunately, it is not protected against NaN nor Inf values.

yes, I tried this… but i guess there’s something wrong with my function… thanks
i’ll figure it out and go back to you when something goes wrong… :slight_smile:

yes, it is expected to be infinite at 0.0 but i’ll figure it out… thanks :slight_smile:
I will ask you later again later…