Connect TGraph points with arrows

Hi. I want to plot a TGraph where the points are connected with arrows. The direction of the arrows should respect the order in which the points were added with TGraph::AddPoint. I think this is not an option for TGraphPainter. Do you have some suggestions on how to do this? or even better, a code draft to start? I’m unsure of which classes exists that could help me with this problem.


ROOT 6.24

void paint_graph_with_arrows(TGraph *gr) {
   double *x = gr->GetX();
   double *y = gr->GetY();
   int n = gr->GetN();
   auto a = new TArrow();
   for (int i=0; i<n-1; i++) a->DrawArrow(x[i],y[i],x[i+1],y[i+1]);

void graph_arrows(){
   TCanvas *c = new TCanvas("c","Paint graph with arrows",700,500);

   const Int_t n = 10;
   TGraph *gr = new TGraph(n);
   gr->SetTitle("Paint graph with arrows");

   Double_t x, y;
   for (Int_t i=0;i<n;i++) {
      x = i*0.123;
      y = 10*sin(x+0.2);


Thank you @couet. Also for answering so fast. This solution is exactly what I needed!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.