# How to adjust range in canvas?

**URL:** <https://root-forum.cern.ch/t/how-to-adjust-range-in-canvas/18048>\
**Category:** ROOT\
**Created:** [August 12, 2014, 11:11pm UTC](https://root-forum.cern.ch/t/how-to-adjust-range-in-canvas/18048 "2014-08-12T23:11:08Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [August 13, 2014, 8:55am UTC](https://root-forum.cern.ch/t/how-to-adjust-range-in-canvas/18048/3 "2014-08-13T08:55:09Z")

</div>

I’m afraid each canvas / pad will have a different name for its “frame” histogram and so you need to play a bit with the TList returned by the “TList \*l = c-\>GetListOfPrimitives();” in order to find it (for example, find the first key which name begins with “frame\_” or maybe it’s sufficient to find the first key which is a TH1D or maybe it’s simply always the second key in the list). Your attached “file.root” has a “frame\_2a3b440”.

[code]#include “TFile.h”  
#include “TCanvas.h”  
#include “TH1.h”  
#include

void make\_plots(std::string ifile)  
{  
TFile f(ifile.c\_str(),“read”);

TCanvas _c = (TCanvas_)f.Get(“test\_can”);  
c-\>SetLogy();

// c-\>Draw();  
// c-\>GetListOfPrimitives()-\>ls();  
// c-\>GetListOfPrimitives()-\>Print();

TH1D \*h = (TH1D \*)c-\>GetPrimitive(“frame\_2a3b440”);  
h-\>SetAxisRange(0, 20, “X”);  
h-\>SetAxisRange(1e-4, 2, “Y”);  
// h-\>SetXTitle(“Something?”);  
h-\>SetYTitle(“What’s this?”);

c-\>Modified(); c-\>Update();  
std::string pdf\_name = ifile + string(".pdf");  
c-\>SaveAs(pdf\_name.c\_str());  
}[/code]

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-adjust-range-in-canvas/18048)._
