I couldn’t quite find out how to do this by searching on Google. I am trying to make a scatter plot with some data and put the y-axis on a logarithmic scale (base 10).
I have two arrays, x and y, of type Double_t. Then I have tried the following lines:
Int_t n = 11000; //The length of my arrays.
TGraph *g = new Tgraph(n,x,y);
TCanvas *c1 = new TCanvas(“My plot”,“Tree Canvas”)
//TCanvas takes two other numerical arguments, w and h. I can set these later.
c1.SetLogy();
c1->Draw();
Something is clearly wrong. I’d appreciate any correction.
there are some typos in the code such as missing “;” and usage of . instead of ->.
In any case the point here is that you need to draw the graph and not the canvas and then change to log scale.
Here you see the working exmple
Int_t n = 11000; //The length of my arrays.
TGraph *g = new TGraph(n);
g->SetPoint(0,1,1);
g->SetPoint(1,10,10);
g->SetPoint(2,100,100);
//....
TCanvas *c1 = new TCanvas("My plot","Tree Canvas");
g->Draw();
c1->SetLogy();
The problems remaining are that this does not produce a scatter plot, and the line
c1->Draw();
produces an error (“Unkown binary” is displayed repeatedly).
Also, ROOT is not accepting
Int_t n = 11000;
Double_t x[n];
The declaration of n (first line) is okay, but it says I cannot declare a Double_t when n is of a variable type. So I have to go Double_t = x[11000]; Could this be causing problems?