#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 void mulgr() { gStyle->SetOptFit(); const char *datain = "C:/data.txt"; const char *dataout = "C:/simulazione/plot.pdf"; TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); //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.7,0.15,0.75,0.2,"brNDC"); TGraphErrors *gr1 = new TGraphErrors(datain,"%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"); gr2->SetMarkerColor(kRed); gr2->SetLineColor(kRed); gr2->SetMarkerStyle(5); gr2->SetMarkerSize(1.3); gr2->SetLineWidth(line); gr2->SetDrawOption("P"); mg->Add(gr2); mg->Draw("LP"); c01->Modified(); c01->Update(); mg->SetTitle("Graph"); mg->GetXaxis()->SetTitle("x"); mg->GetYaxis()->SetTitle("y"); mg->GetYaxis()->SetTitleOffset(offy); mg->GetXaxis()->SetTitleOffset(offx); c01->Modified(); c01->Update(); TLegend* leg = new TLegend(0.15, 0.75, .25, .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(); gPad->Update(); c01->Print(dataout); }