I am using ROOT version 6.30/08 on Ubuntu 20.
I draw several objects on a canvas (TGraph for data plus others for ellipse and lines). I want to set my own drawing limits using SetRangeUser. While the y axis scales correctly, the x-axis does not use the desired limits. I have read the connected topics in the forum, but I am not able the get it right. Here is my python code, which I execute via “pyroot mycode,py”
#define my limits for the plot
xlow = 120
xhigh = 220
ylow = 90
yhigh = 190
Probably your limits are larger than the values in TGraph, and SetRangeUser cannot go “outside” those values. In that case, try with SetLimits instead (note that this is ok for TGraph, not so much for histograms). See
indeed I like to set limits which are smaller/larger than the values of the data in TGraph. This is true for both the x and y axis. In addition I am drawing an ellipse defining a confidence interval (from a PCA analysis). Some regions of the ellipse indeed go beyond the data point from TGraph, so I want to use my own plotting intervals.
The problem was:
using ->GetXaxis()->SetRangeUser(xlow, xhigh) and ->GetYaxis()->SetRangeUser(ylow, yhigh) sets the correct limits for the y axis but not for the x axis
yes, I will provide a stripped down sample code around noon. It will contain also two data files, one for the PCA data, and one for the confidence ellipse. I hope I can append these two files.
I see you are using c3.DrawFrame(xlow, ylow, xhigh, yhigh).
This should draw frame with necessary axes ranges.
After this you should draw graph as graphl.Draw(“P”) - excluding “A” from the option.
if I use the DrawFrame option only (+ “A” instead of “AP”), it will not
display all the graphic elements, e.g. the axes and data points. The
ellipse is displayed.
Appended you find my code and the two files for data and ellipse. With
the present ranges (no DataFrame and only SetRange) it displays wrong x
and y scales.
I tested that with the option “SetRangeUser” and “SetLimits” all is fine.
sorry, I just interchanged “A” and “P” in the “graphl.Draw(” ") statement. When I do it right, the display ranges come out correctly, using only the statement “DrawFrame(xlow,ylow,xhigh,yhigh)” and not “SetRange” etc. The trick then really is to not allow the “A” (=axis) as an argument in graphl.Draw() and only supply “P” for the data points. An elegant solution, which makes perfect sense, but not easy to guess for the casual user.
sorry to bug you again in this matter: With the omission of “A” in the statement graphl(“P”) the scaling is perfect, but the title and axis labels are no more printed (I took exactly your code below). Any suggestion?