21# Create a canvas to draw the graph
 
   22canvas = ROOT.TCanvas("c1", 
"TGraph Example", 800, 600)
 
   27x = numpy.linspace(0, 9, 
n)
 
   28# Compute Y values as the square of X values 
   31# Create a TGraph object using the defined X and Y values 
   34# Get the current number of points in the graph 
   36# Add a new point to the graph at the specified index 
   37graph.SetPoint(
n, 10, 100)
 
   39# Retrieve the coordinates of the 3rd point (index 2) 
   40x_val = graph.GetPointX(2)
 
   41y_val = graph.GetPointY(2)
 
   42print(
f"Point {2}: ({x_val}, {y_val})")
 
   44# Customize graph appearance 
   45graph.SetTitle(
"Example Graph;X-axis Title;Y-axis Title")
 
   46graph.SetMarkerStyle(21)
 
   48graph.SetMarkerColor(4)
 
   53# Draw the graph with axes ("A"), lines ("L"), and points ("P") 
   56# Save the graph as a PNG file 
   57canvas.SaveAs(
"tgraph_example.png")
 
   60## Advanced Example: Comparing Two Datasets 
   67# Define benchmark data for Dataset 1 using NumPy arrays
 
   68dataset1_x_values = numpy.array([32, 64, 128, 256, 512, 1024, 2048], dtype=float)
 
   69dataset1_y_values = numpy.array([2, 3, 7, 13, 26, 48, 100], dtype=float)
 
   71# Define benchmark data for Dataset 2 using NumPy arrays
 
   72dataset2_x_values = numpy.array([32, 64, 128, 256, 512, 1024, 2048], dtype=float)
 
   73dataset2_y_values = numpy.array([2, 3, 7, 13, 26, 47, 92], dtype=float)
 
   75# Create TGraph objects for Dataset 1 and Dataset 2
 
   76graph1 = ROOT.TGraph(len(dataset1_x_values), dataset1_x_values, dataset1_y_values)
 
   77graph2 = ROOT.TGraph(len(dataset2_x_values), dataset2_x_values, dataset2_y_values)
 
   79# Configure canvas dimensions for displaying the comparative plot
 
   80width, height = 1920, 1080
 
   81canvas = ROOT.TCanvas("c", 
"Datasets Comparison", 
width, 
height)
 
   82# Left, Right, Bottom, Top margins
 
   83canvas.SetMargin(0.08, 0.05, 0.15, 0.09)
 
   85# Retrieve y-axis minimum and maximum values to set dynamic axis ranges for the plot 
   90graph1.SetTitle(
"TGraph dataset comparison plot title")
 
   91graph1.GetXaxis().SetTitle(
"X Axis Title")
 
   92graph1.GetXaxis().SetTitleSize(0.04)
 
   93graph1.GetXaxis().SetTitleOffset(1.3)
 
   94graph1.GetXaxis().SetLabelSize(0.03)
 
   96# Hide default x-axis labels and ticks to customize axis appearance 
   97graph1.GetXaxis().SetLabelSize(0)
 
   98graph1.GetXaxis().SetTickLength(0)
 
  100graph1.GetYaxis().SetTitle(
"Y Axis Title")
 
  101graph1.GetYaxis().SetTitleSize(0.04)
 
  102graph1.GetYaxis().SetTitleOffset(0.7)
 
  103graph1.GetYaxis().SetLabelSize(0.03)
 
  104# Ensure y-axis includes zero 
  116# Add custom x-axis labels and ticks to align with data points for better readability 
  164canvas.SaveAs(
"tgraph_comparison.pdf")
 
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
 
Option_t Option_t SetLineWidth
 
Option_t Option_t SetTextSize
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
 
Option_t Option_t SetLineColor
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
 
Option_t Option_t SetTextFont
 
Option_t Option_t SetMarkerStyle
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
 
Option_t Option_t TPoint TPoint const char text
 
A TGraph is an object made of two arrays X and Y with npoints each.
 
To draw Mathematical Formula.
 
This class displays a legend box (TPaveText) containing several legend entries.
 
Use the TLine constructor to create a simple line.
 
RooCmdArg Save(bool flag=true)
 
leg AddEntry(h1,"Histogram filled with random numbers","f")
 
Vector Rotate(const Vector &v, const RotationMatrix &rot)
rotation on a generic vector using a generic rotation class.
 
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
 
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.