91187
November 24, 2016, 10:54am
1
I attach the output of my current code, where there is a line connecting two sets of data points (one set is at x=620, one at x=1000).
My code reads:
g = ROOT.TGraph(len(exp_array),exp_array,dt_array)
g.SetMarkerStyle(1)
g.SetMarkerSize(1)
g.Draw(“AP”)
I looked (root.cern.ch/doc/master/classTGraphPainter.html ) for which draw option to choose, and “AP” seems to be what I want.
I think that since I am using PyROOT, its possible that only some of the draw options are supported ("*", for example).
Does anybody know how to get rid of this line connecting two sets of data points?
couet
November 24, 2016, 1:07pm
2
The option “AP” will draw your graph with Points only. Do you have a more complete script showing the problem ?
1 Like
91187
November 24, 2016, 1:32pm
3
Here is a sample script with the two text files
run like this:
$ python tgraphex.py --filename 1000.txt 620.txt
1000.txt (351 KB)
620.txt (527 KB)
tgraphex.py (2.18 KB)
couet
November 24, 2016, 1:43pm
4
Yes I see this line … What about if you use a simpler script.
Like the following one:
void graph() {
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2)-5;
}
TGraph *gr = new TGraph(n,x,y);
gr->SetMarkerStyle(20);
gr->Draw("AP");
}
For me it gives only dots.
91187
November 24, 2016, 4:13pm
5
Can you give me a similar code to try with Python? It works fine for me in C++ (I see the dots)
couet
November 24, 2016, 4:22pm
6
you can just take your initial script as example and produce a translation of the simple example .
even do a more simple one:
void graph() {
TGraph *gr = new TGraph();
gr->SetPoint(0,0.,0.);
gr->SetPoint(1,1.,1.);
gr->SetPoint(2,2.,2.);
gr->SetPoint(3,3.,3.);
gr->SetMarkerStyle(20);
gr->Draw("AP");
}
91187
November 24, 2016, 4:40pm
7
Sure, I just think some things are getting lost in my translation from C++ to Python (I’m new at coding). Have you been able to write an example in Python that produces the dots? I have tried and have not been able to, even with your simpler examples in C++.
couet
November 25, 2016, 8:38am
8
this one produces dot:
from ROOT import *
c = TCanvas("c","c")
gr = TGraph()
gr.SetPoint(0,0.,0.)
gr.SetPoint(1,1.,1.)
gr.SetPoint(2,2.,2.)
gr.SetPoint(3,3.,3.)
gr.SetMarkerStyle(20)
gr.Draw("AP")
c.Print("c.pdf")