# Getting root to display graphs

**URL:** <https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598>\
**Category:** Newbie\
**Tags:** graphics\
**Created:** [February 5, 2019, 2:58pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598 "2019-02-05T14:58:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colton\_Graham](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@Colton\_Graham](https://root-forum.cern.ch/u/Colton_Graham)\
**Post date:** [February 5, 2019, 2:58pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598/1 "2019-02-05T14:58:05Z")

</div>

Hi! So, I’m new to root, and I’m trying to get root to display a graph using the macro

```auto
void graph(){
    gROOT->SetStyle("Plain");
    TF1 f1("f1","sin(x)/x",0.,10.);
    f1.Draw();
}

```

but every time I run the macro, the canvas shows up empty. I can use the commands at the root prompt and get it to display the graph, but not from a macro. Can anyone help? I’m trying to run Root 6.16 on a windows 10 machine. Thanks!

---

<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 5, 2019, 3:10pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598/2 "2019-02-05T15:10:05Z")

</div>

[TF1::DrawCopy](https://root.cern.ch/doc/master/classTF1.html#ab71e20c7fa0e2625f92b5ea29ceca83e)

BTW. You should learn about the lifetime of “stack-based” and “heap-based” objects in C++.

---

<div class="post-metadata">

**Author:** ![Colton\_Graham](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@Colton\_Graham](https://root-forum.cern.ch/u/Colton_Graham)\
**Post date:** [February 5, 2019, 3:14pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598/3 "2019-02-05T15:14:05Z")

</div>

Thanks, but I don’t follow your second statement. I’m only using the one TF1, so what’s the problem with using draw?

---

<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 5, 2019, 3:19pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598/4 "2019-02-05T15:19:28Z")

</div>

Your “stack-based” TF1 object is automatically deleted when your “graph” function finishes.

---

<div class="post-metadata">

**Author:** ![Colton\_Graham](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@Colton\_Graham](https://root-forum.cern.ch/u/Colton_Graham)\
**Post date:** [February 5, 2019, 3:20pm UTC](https://root-forum.cern.ch/t/getting-root-to-display-graphs/32598/5 "2019-02-05T15:20:08Z")

</div>

Oh, it already goes out of scope, and the canvas doesn’t hold the image? Okay, thanks!
