TGraphErrors* graph = new TGraphErrors("data.txt", "%lg %lg %lg %lg"); TAxis* xAxis = graph->GetXaxis(); xAxis->SetTitle("Voltage (V)");
TCanvas* canvas = new TCanvas("canvas", "Graph Example", 800, 600); TGraphErrors* graph = new TGraphErrors("data.txt", "%lg %lg %lg %lg"); TAxis* xAxis = graph->GetXaxis(); xAxis->SetRangeUser(0, 10); graph->Draw("AP"); canvas->SaveAs("graph.png");In this example, we create a TCanvas object named canvas and set its size to 800x600 pixels. We then create a TGraphErrors object named graph by reading data from a file called data.txt. We retrieve the X-axis using the GetXaxis function and set its range to 0 to 10 using the SetRangeUser function. Finally, we draw the graph with error bars using the Draw function and save it as a PNG file named graph.png using the SaveAs function. The package library for this class is ROOT.