# How to change the position of axes of a graph

**URL:** <https://root-forum.cern.ch/t/how-to-change-the-position-of-axes-of-a-graph/51970>\
**Category:** Newbie\
**Tags:** root\
**Created:** [October 14, 2022, 9:04pm UTC](https://root-forum.cern.ch/t/how-to-change-the-position-of-axes-of-a-graph/51970 "2022-10-14T21:04:07Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 16, 2022, 9:26am UTC](https://root-forum.cern.ch/t/how-to-change-the-position-of-axes-of-a-graph/51970/14 "2022-10-16T09:26:04Z")

</div>

Maybe @couet has a better idea.

```cpp
{
  // create the graph
  Double_t x[3] = {0., 400., 2700.};
  Double_t y[3] = {2.3, -0.1, -0.4};
  TGraph *g = new TGraph(3, x, y);
  Double_t xmin = -300., xmax = 3100.; // x-axis range
  Double_t ymin = -0.7, ymax = 2.6; // y-axis range
  // create and draw the canvas
  TCanvas *c = new TCanvas("c", "c");
  Double_t r = Double_t(c->GetWw()) / Double_t(c->GetWh()); // aspect ratio
  Double_t ml = 0.05; // (bottom, top, left, right) margin length (percentage)
  Double_t al = 0.04; // arrow length (percentage of the pad height)
  Double_t dx = (xmax - xmin) / (1. - 2. * ml - al / r);
  Double_t dy = (ymax - ymin) / (1. - 2. * ml - al);
  c->Range(xmin - dx * ml, ymin - dy * ml,
           xmax + dx * (ml + al / r), ymax + dy * (ml + al));
  // draw the graph
  g->Draw("L*");
  // create and draw the x-axis
  TGaxis *ax = new TGaxis(xmin, 0., xmax, 0., xmin, xmax, 510, "-+S");
  ax->SetTickLength(al * r / 4.);
  ax->ChangeLabel(1, -1, -1, -1, -1, -1, " "); // remove "0"
  ax->SetLabelOffset(-0.075);
  ax->SetTitle("Retarding Potential");
  ax->SetTitleOffset(-1.5);
  ax->Draw();
  TArrow *axa = new TArrow(xmax, 0., xmax + dx * al / r, 0., al, "|>");
  axa->SetAngle(30);
  axa->Draw();
  // create and draw the y-axis
  TGaxis *ay = new TGaxis(0., ymin, 0., ymax, ymin, ymax, 510, "-+S");
  ay->SetTickLength(al / 4.);
  ay->ChangeLabel(2, -1, -1, -1, -1, -1, " "); // remove "0"
  ay->SetTitle("Photocell current");
  ay->SetTitleOffset(-1.3);
  ay->Draw();
  TArrow *aya = new TArrow(0., ymax, 0., ymax + dy * al, al, "|>");
  aya->SetAngle(30);
  aya->Draw();
}

```

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-change-the-position-of-axes-of-a-graph/51970)._
