Set first axis number to draw

Dear experts,

I need a very simple help in setting the first point to be drawn of a X-axis of a TGraph. In particular, not the default ‘0’ value but the ‘1’ or other.
Moreover, how can I set to draw only odd points on the X-axis of my TGraph.

Thank you a lot for your collaboration


Please read tips for efficient and successful posting and posting code

_ROOT Version: ROOT 6.24/00
Platform: Windows 10

The best is to use ChangeLabel. If you have a little example I can modify It to show you how to proceed.

Thank you a lot for your help.

With the following code I obtain the plots (o something like that):

    char nmMG[10];
    sprintf(nmMG, "Q2 M%d", Sz + 2);
    TMultiGraph* mg_comp_Stz_Q2 = new TMultiGraph();
    mg_comp_Stz_Q2->SetTitle(nmMG);

	int ngr_yrs = 2;//yrs= 2018, 2022
	TGraph** gr_comp_Stz_Q2 = new TGraph * [ngr_yrs];
	for (int ys = 0; ys < ngr_yrs; ys++) {
		gr_comp_Stz_Q2[ys] = new TGraph(nTotCha_Q, XY_gr_comp_Stz_Q2_2018_22[ys][0], XY_gr_comp_Stz_Q2_2018_22[ys][1]);
		gr_comp_Stz_Q2[ys]->SetLineColor(kBlack);
		gr_comp_Stz_Q2[ys]->SetMarkerStyle(20);
		gr_comp_Stz_Q2[ys]->SetMarkerSize(.7);
		if (ys == 0) gr_comp_Stz_Q2[ys]->SetMarkerColor(kBlue);
		if (ys == 1) gr_comp_Stz_Q2[ys]->SetMarkerColor(kRed);
		mg_comp_Stz_Q2->Add(gr_comp_Stz_Q2[ys], "lp");
	}
	mg_comp_Stz_Q2->Draw("ALP");
  • They are about 70 points, thus I would like having the first number ob the X-axis equal to 1 and not to 0

Thank you again for your help

Can you provide à minimal working example showing the plot you get and I will modify it ?

I am sorry, I forgot to put plot:

Try:

mg_comp_Stz_Q2->Draw("ALP");
gPad->Modified(); gPad->Update();
mg_comp_Stz_Q2->GetHistogram()->GetXaxis()->SetLimits(0.5, 69.5); /* or maybe (1., 70.) */
gPad->Modified(); gPad->Update();

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