#include "TStyle.h" #include "TTimer.h" #include "Riostream.h" #include "TCanvas.h" #include "TGraph.h" #include "TROOT.h" #include "TGraphErrors.h" #include "TFrame.h" #include "TAxis.h" void grapherrors(){ // gStyle->SetOptStat(10); gStyle->SetOptFit(111); gStyle->SetFrameBorderMode(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetFrameFillColor(10); gStyle->SetPadColor(10); gStyle->SetCanvasColor(10); gStyle->SetTitleColor(10); gStyle->SetStatColor(10); gStyle->SetFillColor(10); gROOT->Reset(); TCanvas * c1 = new TCanvas("c1","A Simple Graph",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); const Int_t n = 4; Float_t x[n] = {-0.22, 0.05, 0.25, 0.35}; Float_t y[n] = {1.,2.9,5.6,7.4}; Float_t ex[n] = {.5,.1,.07,.07}; Float_t ey[n] = {.8,.7,.6,.5}; c1->cd(); TGraph * gr1 = new TGraph(n,x,y); gr1->SetTitle("TGraph"); gr1->SetMarkerColor(4); gr1->SetMarkerStyle(21); gr1->GetXaxis()->SetTitle("x"); //Add a title to the axis gr1->GetYaxis()->SetTitle("y"); gr1->Draw("ALP"); TCanvas * c2 = new TCanvas("c2","A Simple Graph with error bars",910,10,700,500); c2->cd(); c2->SetFillColor(8); c2->SetGrid(); c2->GetFrame()->SetFillColor(21); c2->GetFrame()->SetBorderSize(12); TGraph * gr2 = new TGraphErrors(n,x,y,ex,ey); gr2->SetTitle("TGraphErrors Example"); gr2->SetMarkerColor(4); gr2->SetMarkerStyle(21); gr2->Draw("ALP"); return; }