#include "TCanvas.h" #include "TPad.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TAxis.h" #include "TLegend.h" #include "TLatex.h" #include "TROOT.h" #include "TRatioPlot.h" #include void mulgr() { gStyle->SetOptFit(); int YLabelSize=25; int XLabelSize=25; int YTitleSize=25; int XTitleSize=25; const char *datain = "C:/data.txt"; const char *dataout = "C:/simulazione/plot.pdf"; TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); gStyle->SetTitleSize(0.1,"t"); TPad *pad1 = new TPad("pad1", "pad1", 0.0, 0.5, 1.0, 1.); pad1->SetGridx(); // Vertical grid pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); //c01->SetGrid(); TMultiGraph *mg = new TMultiGraph(); float offx=1.3; float offy=1.3; //float margr=0.08; float w=3; // float margl=0.12; float line=2; // gPad->SetLeftMargin(margl); //gPad->SetRightMargin(margr); TPaveText *t=new TPaveText(0.8,0.15,0.85,0.2,"brNDC"); TGraphErrors *gr1 = new TGraphErrors(datain,"%lg %lg %*lg %*lg"); gr1->SetMarkerColor(kBlue); gr1->SetLineColor(kBlue); gr1->SetMarkerStyle(3); gr1->SetMarkerSize(1.3); gr1->SetLineWidth(line); gr1->SetDrawOption("AP"); mg->Add(gr1); TGraphErrors *gr2 = new TGraphErrors(datain,"%lg %*lg %lg %*lg"); gr2->SetMarkerColor(kRed); gr2->SetLineColor(kRed); gr2->SetMarkerStyle(5); gr2->SetMarkerSize(1.3); gr2->SetLineWidth(line); gr2->SetDrawOption("P"); mg->Add(gr2); mg->Draw("ALP"); c01->Modified(); c01->Update(); mg->GetHistogram()->SetTitle("Global title"); //mg->SetTitle("Graph Title"); mg->GetXaxis()->SetTitle("x"); mg->GetYaxis()->SetTitle("y"); mg->GetYaxis()->SetTitleOffset(offy); mg->GetXaxis()->SetTitleOffset(offx); mg->GetXaxis()->SetTitleSize(XTitleSize); mg->GetYaxis()->SetTitleSize(YTitleSize); /* mg->GetYaxis()->SetLabelSize(YLabelSize); mg->GetXaxis()->SetLabelSize(XLabelSize);*/ c01->Modified(); c01->Update(); TLegend* leg = new TLegend(0.15, 0.75, .2, .85); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(gr1, "gr1", "AP"); leg->AddEntry(gr2, "gr2", "P"); leg->Draw(); gPad->Update(); gPad->Update(); t->AddText("Text"); t->Draw(); c01->cd(); c01->Update(); TPad *pad2 = new TPad("pad2", "pad2", 0.0, 0.0, 1., 0.5); pad2->SetTopMargin(0.01); pad2->SetBottomMargin(1); pad2->SetGridx(); // vertical grid pad2->Draw(); pad2->cd(); // pad2 becomes the current pad TGraphErrors *ratio = new TGraphErrors(datain,"%lg %*lg %*lg %lg"); ratio->SetMarkerColor(kGreen+3); ratio->SetLineColor(kGreen+3); ratio->SetLineWidth(2); ratio->SetMarkerSize(2); ratio->SetMarkerStyle(29); ratio->Draw("ALP"); ratio->SetTitle(""); ratio->GetXaxis()->SetTitle("x"); ratio->GetYaxis()->SetTitle("ratio"); ratio->GetYaxis()->SetTitleOffset(offy); ratio->GetXaxis()->SetTitleOffset(offx); ratio->GetXaxis()->SetTitleSize(XTitleSize); ratio->GetYaxis()->SetTitleSize(YTitleSize); // ratio->GetYaxis()->SetLabelSize(YLabelSize); //ratio->GetXaxis()->SetLabelSize(XLabelSize); c01->Modified(); c01->Update(); TLegend* leg2 = new TLegend(0.15, 0.75, .2, .85); leg2->SetHeader("Legend"); leg2->SetNColumns(1); leg2->AddEntry(ratio, "Difference", "ALP"); leg2->Draw(); gPad->Update(); gPad->Update(); // gPad->Update(); c01->Print(dataout); }