# TGraph Drawn like TVectorD

**URL:** <https://root-forum.cern.ch/t/tgraph-drawn-like-tvectord/15579>\
**Category:** ROOT\
**Created:** [February 1, 2013, 8:53pm UTC](https://root-forum.cern.ch/t/tgraph-drawn-like-tvectord/15579 "2013-02-01T20:53:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [February 1, 2013, 9:43pm UTC](https://root-forum.cern.ch/t/tgraph-drawn-like-tvectord/15579/2 "2013-02-01T21:43:09Z")

</div>

[code]#include “TVectorD.h”  
#include “TGraph.h”

TGraph \*TVectorD2TGraph(TVectorD \*v)  
{  
if (!v) return ((TGraph \*)0); // just a precaution  
TGraph \*g = new TGraph( (2 \* v-\>GetNoElements()) );  
for (Int\_t i = 0; i \< v-\>GetNoElements(); i++) {  
(g-\>GetX())[(2 \* i)] = ((Double\_t)i);  
(g-\>GetX())[(2 \* i + 1)] = ((Double\_t)(i + 1));  
(g-\>GetY())[(2 \* i + 1)] = (g-\>GetY())[(2 \* i)] = (\*v)[i];  
}  
// g-\>Draw(“AL”);  
return g;  
}[/code] You can then “scale” the “X” coordinates of the points of the returned TGraph as you wish. See, for example, [url][Shifting TMultigraph on x-axis to the same starting point](https://root-forum.cern.ch/t/shifting-tmultigraph-on-x-axis-to-the-same-starting-point/15555/5) (and don’t forget [url][Shifting TMultigraph on x-axis to the same starting point](https://root-forum.cern.ch/t/shifting-tmultigraph-on-x-axis-to-the-same-starting-point/15555/14)

BTW. If you want to “scale” the “X” axis of the drawn histogram:  
TH1D _h = static\_cast\<TH1D_\>(gPad-\>FindObject(“TVectorD”));  
you need to remember that it has “fix bin sizes” along “X”, so you can only modify “xmin” and “xmax” of its “X” axis (hence the “scaling function” must be linear and “xmax” must remain greater than “xmin”). See: [url][Can we shift histogram for several channels?](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2)

---

_[View the full topic](https://root-forum.cern.ch/t/tgraph-drawn-like-tvectord/15579)._
