TCanvas canvas; TGraph graph(5); // create a graph with 5 points graph.SetPoint(0, 0, 0); graph.SetPoint(1, 1, 1); graph.SetPoint(2, 2, 4); graph.SetPoint(3, 3, 9); graph.SetPoint(4, 4, 16); graph.Draw("ALP"); // draw the graph
TCanvas canvas; TGraph graph("data.txt"); // create a graph from data in a file graph.Draw("ALP"); // draw the graph
TCanvas canvas; TGraph graph(5); graph.SetPoint(0, 0, 0); graph.SetPoint(1, 1, 1); graph.SetPoint(2, 2, 4); graph.SetPoint(3, 3, 9); graph.SetPoint(4, 4, 16); graph.SetLineColor(kRed); // set the line color to red graph.SetLineWidth(2); // set the line width to 2 graph.SetMarkerColor(kBlue); // set the marker color to blue graph.SetMarkerStyle(20); // set the marker style to a circle graph.SetMarkerSize(1.5); // set the marker size to 1.5 graph.Draw("ALP"); // draw the graphThis code creates a graph with 5 points and sets the line and marker styles. The `SetLineColor` method sets the color of the line connecting the points, `SetLineWidth` sets the width of the line, `SetMarkerColor` sets the color of the markers at each point, `SetMarkerStyle` sets the shape of the markers, and `SetMarkerSize` sets the size of the markers. Overall, the TGraph class is a useful tool for creating and modifying graphs in the C++ programming language.