Hi
I have 4 .dat files each with 2 arrays. In each files, First one array corresponds to Voltage and second one correspond to Gain at different conditions. I want to make a plot of Gain vs. Voltage at one graph (not individually).
Can any one help me out with a code?
I wrote the following one but it doesnt work.
{
TCanvas *c1= new TCanvas ("c1", "", 700, 600);
TMultiGraph *mg= new TMultiGraph ();
TGraph gr0 ("CH0.dat", "%lg %lg");
gr0.SetMarkerStyle (kFullCircle);
gr0.SetMarkerColor (kRed);
gr0.Draw ("");
TGraph gr1 ("CH1.dat", "%lg %lg");
gr1.SetMarkerStyle (kFullCircle);
gr1.SetMarkerColor (kBlue);
gr1.Draw("");
TGraph gr2 ("CH2.dat", "%lg %lg");
gr2.SetMarkerStyle (kMultiply);
gr2.SetMarkerColor (kBlack);
gr2.Draw("");
TGraph gr3 ("CH3.dat", "%lg %lg");
gr3.SetMarkerStyle (kStar);
gr3.SetMarkerColor (kBlack);
gr3.Draw ("");
mg->Add ("gr0");
mg->Add ("gr1");
mg->Add ("gr2");
mg->Add ("gr3");
mg->Draw("");
}
[code]{
TGraph *gr0 = new TGraph (“CH0.dat”, “%lg %lg”);
gr0->SetMarkerStyle (kFullCircle);
gr0->SetMarkerColor (kRed);
TGraph *gr1 = new TGraph (“CH1.dat”, “%lg %lg”);
gr1->SetMarkerStyle (kFullCircle);
gr1->SetMarkerColor (kBlue);
TGraph *gr2 = new TGraph (“CH2.dat”, “%lg %lg”);
gr2->SetMarkerStyle (kMultiply);
gr2->SetMarkerColor (kBlack);
TGraph *gr3 = new TGraph (“CH3.dat”, “%lg %lg”);
gr3->SetMarkerStyle (kStar);
gr3->SetMarkerColor (kBlack);
TMultiGraph *mg = new TMultiGraph();
mg->Add (gr0);
mg->Add (gr1);
mg->Add (gr2);
mg->Add (gr3);
TCanvas *c1 = new TCanvas (“c1”, “”, 700, 600);
mg->Draw(“AP”);
}[/code]
Thank you so much. It worked.
However I am not able to set colors of my choice for pol1 fit lines. i used the following code: [code]{
TGraph *gr0 = new TGraph (“CH0.dat”, “%lg %lg”);
gr0->SetMarkerStyle (kFullCircle);
gr0->SetMarkerColor (kRed);
gr0->Fit(“pol1”);
gr0->SetLineColor(kRed);
TGraph *gr1 = new TGraph (“CH1.dat”, “%lg %lg”);
gr1->SetMarkerStyle (kFullCircle);
gr1->SetMarkerColor (kBlue);
gr1->Fit(“pol1”);
gr1->SetLineColor (kBlue);
TGraph *gr2 = new TGraph (“CH2.dat”, “%lg %lg”);
gr2->SetMarkerStyle (kMultiply);
gr2->SetMarkerColor (kBlack);
gr2->Fit(“pol1”);
gr2->SetLineColor (kBlack);
TGraph *gr3 = new TGraph (“CH3.dat”, “%lg %lg”);
gr3->SetMarkerStyle (kStar);
gr3->SetMarkerColor (kGreen);
gr3->Fit(“pol1”);
gr3->SetLineColor (kGreen);
TMultiGraph *mg = new TMultiGraph();
mg->SetTitle (“Gain vs. Voltage”);
mg->Add (gr0);
mg->Add (gr1);
mg->Add (gr2);
mg->Add (gr3);
TCanvas *c1 = new TCanvas (“c1”, “”, 700, 600);
mg->Draw(“AP”);
}
[/code]
Also, before whenever I wrote
TGraph *gr0 = new TGraph ()
gr0->Draw ()
an error message used to pop up saying TGraph doesnt belong to POINTER class and I should use Dots (.) instead… But right now its working with Pointers… Could you please explain me why?
// ...
gr0->GetFunction("pol1")->SetLineColor(kRed);
// ...
gr1->GetFunction("pol1")->SetLineColor(kBlue);
// ...
gr2->GetFunction("pol1")->SetLineColor(kBlack);
// ...
gr3->GetFunction("pol1")->SetLineColor(kGreen);
// ...
Thank you so much. It worked now.