Draw function and graph at the same canvas

Hello, I am trying to draw a graph and a function at the same canvas, but I can only see the graph. The option “same” is not working. Can somebody please help me?
This is my code:

{

TGraphAsymmErrors *grae = new TGraphAsymmErrors(42);
   grae->SetName("gr_exp1");
   grae->SetTitle("AMS02(2011/05-2012/12)");
   grae->SetFillColor(1);
   grae->SetFillStyle(0);
   grae->SetMarkerStyle(2);
   grae->SetMarkerSize(1.2);
   grae->SetPoint(0,10.33,0.0519);
   grae->SetPointError(0,0.38,0.4,0.0006324555,0.0006324555);
   grae->SetPoint(1,11.12,0.0528);
   grae->SetPointError(1,0.39,0.42,0.000728011,0.000728011);
   grae->SetPoint(2,11.95,0.0535);
   grae->SetPointError(2,0.41,0.44,0.000728011,0.000728011);
   grae->SetPoint(3,12.82,0.0549);
   grae->SetPointError(3,0.43,0.45,0.0008246211,0.0008246211);
   grae->SetPoint(4,13.72,0.0551);
   grae->SetPointError(4,0.45,0.47,0.0008246211,0.0008246211);
   grae->SetPoint(5,14.66,0.0543);
   grae->SetPointError(5,0.47,0.49,0.0009219544,0.0009219544);
   grae->SetPoint(6,15.64,0.0556);
   grae->SetPointError(6,0.49,0.51,0.001019804,0.001019804);
   grae->SetPoint(7,16.65,0.0583);
   grae->SetPointError(7,0.5,0.53,0.001140175,0.001140175);
   grae->SetPoint(8,17.7,0.0586);
   grae->SetPointError(8,0.52,0.55,0.001140175,0.001140175);
   grae->SetPoint(9,18.8,0.0592);
   grae->SetPointError(9,0.55,0.57,0.001236932,0.001236932);
   grae->SetPoint(10,19.94,0.0634);
   grae->SetPointError(10,0.57,0.6,0.001334166,0.001334166);
   grae->SetPoint(11,21.14,0.0618);
   grae->SetPointError(11,0.6,0.62,0.001431782,0.001431782);
   grae->SetPoint(12,22.4,0.0653);
   grae->SetPointError(12,0.64,0.67,0.001529706,0.001529706);
   grae->SetPoint(13,23.74,0.0651);
   grae->SetPointError(13,0.67,0.71,0.001627882,0.001627882);
   grae->SetPoint(14,25.14,0.0657);
   grae->SetPointError(14,0.69,0.73,0.001627882,0.001627882);
   grae->SetPoint(15,26.59,0.0668);
   grae->SetPointError(15,0.72,0.75,0.001824829,0.001824829);
   grae->SetPoint(16,28.09,0.0694);
   grae->SetPointError(16,0.75,0.78,0.002022375,0.002022375);
   grae->SetPoint(17,29.64,0.071);
   grae->SetPointError(17,0.77,0.81,0.002137756,0.002137756);
   grae->SetPoint(18,31.26,0.0701);
   grae->SetPointError(18,0.81,0.84,0.002236068,0.002236068);
   grae->SetPoint(19,32.93,0.0707);
   grae->SetPointError(19,0.83,0.87,0.00245153,0.00245153);
   grae->SetPoint(20,34.67,0.0718);
   grae->SetPointError(20,0.87,0.9,0.00264764,0.00264764);
   grae->SetPoint(21,36.47,0.0747);
   grae->SetPointError(21,0.9,0.93,0.002745906,0.002745906);
   grae->SetPoint(22,38.67,0.0794);
   grae->SetPointError(22,1.27,1.33,0.002668333,0.002668333);
   grae->SetPoint(23,41.66,0.0802);
   grae->SetPointError(23,1.66,1.73,0.002692582,0.002692582);
   grae->SetPoint(24,45.16,0.0817);
   grae->SetPointError(24,1.77,1.85,0.002983287,0.002983287);
   grae->SetPoint(25,48.9,0.0856);
   grae->SetPointError(25,1.89,1.97,0.003298485,0.003298485);
   grae->SetPoint(26,52.88,0.0891);
   grae->SetPointError(26,2.01,2.1,0.003883298,0.003883298);
   grae->SetPoint(27,57.12,0.0957);
   grae->SetPointError(27,2.14,2.24,0.00422019,0.00422019);
   grae->SetPoint(28,61.65,0.0962);
   grae->SetPointError(28,2.29,2.38,0.004827007,0.004827007);
   grae->SetPoint(29,66.46,0.0978);
   grae->SetPointError(29,2.43,2.54,0.005166237,0.005166237);
   grae->SetPoint(30,71.6,0.1032);
   grae->SetPointError(30,2.6,2.7,0.005869412,0.005869412);
   grae->SetPoint(31,77.09,0.0985);
   grae->SetPointError(31,2.79,2.91,0.006356099,0.006356099);
   grae->SetPoint(32,82.94,0.1023);
   grae->SetPointError(32,2.94,3.06,0.006844706,0.006844706);
   grae->SetPoint(33,89.19,0.112);
   grae->SetPointError(33,3.19,3.31,0.007648529,0.007648529);
   grae->SetPoint(34,96.17,0.1189);
   grae->SetPointError(34,3.67,3.83,0.008276473,0.008276473);
   grae->SetPoint(35,107.2,0.1118);
   grae->SetPointError(35,7.2,7.9,0.006957011,0.006957011);
   grae->SetPoint(36,123.3,0.1142);
   grae->SetPointError(36,8.2,8.8,0.008443341,0.008443341);
   grae->SetPoint(37,141.4,0.1215);
   grae->SetPointError(37,9.3,10.1,0.01049952,0.01049952);
   grae->SetPoint(38,162.1,0.1364);
   grae->SetPointError(38,10.6,11.4,0.01317004,0.01317004);
   grae->SetPoint(39,189,0.1485);
   grae->SetPointError(39,15.5,17,0.01459075,0.01459075);
   grae->SetPoint(40,231.4,0.153);
   grae->SetPointError(40,25.4,28.6,0.01892115,0.01892115);
   grae->SetPoint(41,301.6,0.155);
   grae->SetPointError(41,41.6,48.4,0.02512051,0.02512051);

grae->Draw("AP");

TF1 *f5 = new TF1("f5","0.01*x^(-0.4)",10,350);

f5->Draw("same");

}

Try: TF1 *f5 = new TF1("f5", "0.018 * pow(x, 0.4)", 10, 350);

I tried your macro. I notice that f5 is out of the range of the graph so even with Wile suggestion you will see nothing. I see something with;

TF1 *f5 = new TF1("f5","pow(x,-0.4)",10,350);
f5->Draw("same");

:eyeglasses: for you so that you start to see something with my suggestion (both the original one and the improved edited one).

1 Like

Thank you. Now I can see what was wrong. It was the Y range.

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