# Drawing legend zooms out x-axis to start at 0; how to reset it?

**URL:** <https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597>\
**Category:** Newbie\
**Tags:** jsroot\
**Created:** [September 7, 2024, 2:46pm UTC](https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597 "2024-09-07T14:46:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/4491bb/32.png) [@nsj](https://root-forum.cern.ch/u/nsj)\
**Post date:** [September 7, 2024, 2:46pm UTC](https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597/1 "2024-09-07T14:46:02Z")

</div>

I am using JSROOT to display several TMultiGraphs online. Without legends, they look ok, but I need legends. I am reading the multigraphs from a root file and constructing the legends in JS.

All of these multigraphs have x-values starting above zero. Without the legends, the autorange works nicely and the graph automatically shows a sensible x-axis range. When I started to add legends, this changed unexpectedly.

I find that when I draw each multigraph before its legend, then just the first multigraph gets its x-axis range reset to start at 0. However if I draw each legend before its multigraph, then all of the multigraphs unexpectedly have their x-axis reset to start at 0.

It looks like the TGraphPainter’s xmin is getting overwritten but Idk if that is my fault or JSROOT’s.

How can I reset the x-axis to my preferred values?

The JSROOT example on zooming didn’t seem to be directly applicable to multigraphs. Also it was a bit too complicated. I would really like an example to modify that does something like GetXaxis()-\>SetRangeUser(3,5), if anyone has a code snippet to share, I’d be grateful.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [September 7, 2024, 4:26pm UTC](https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597/2 "2024-09-07T16:26:34Z")

</div>

Dear Naomi,

Thanks for the post and welcome to the ROOT Community!

I would defer this very specific question to the JSROOT expert, @linev

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![nsj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/4491bb/32.png) [@nsj](https://root-forum.cern.ch/u/nsj)\
**Post date:** [September 7, 2024, 6:14pm UTC](https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597/3 "2024-09-07T18:14:37Z")

</div>

Thanks! After a hard reload it works as intended with the 2 lines in this order:

```auto
let gpainter = await draw(divname, obj[i], 'ap;gridx;gridy;');     
if (drawlegend) await draw(divname,leg[i]);

```

If I swap the lines, then the x-axes all start from 0.

I would still like to know how to specify the x-axis limits, please.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [September 9, 2024, 7:23am UTC](https://root-forum.cern.ch/t/drawing-legend-zooms-out-x-axis-to-start-at-0-how-to-reset-it/61597/4 "2024-09-09T07:23:28Z")

</div>

> [@nsj](#):
>
> I would still like to know how to specify the x-axis limits, please.

Hi,

Are you drawing graphs or multigraphs?  
You trying to overlap several of them?

When creating `TMultiGraphs`, you can specify user range in ROOT macro as:

```auto
   auto mg = new TMultiGraph();
   mg->Add(gr1);
   mg->Add(gr2);
   mg->GetXaxis()->SetRangeUser(0, 0.8);

```

You also can change zoom in JSROOT after multigraph and legend are drawn.  
Just add at the end of your code:

```auto
gpainter.getFramePainter().zoom(0, 0.8);

```

To create legend for your drawings you can try to use `drawLegend` method as:

```auto
gpainter.getPadPainter().drawLegend();

```
