# TGraph Not Working, Returning Error Message: could not convert argument to buffer or nullptr

**URL:** <https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [December 5, 2022, 4:38am UTC](https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635 "2022-12-05T04:38:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RNugent](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/53a042/32.png) [@RNugent](https://root-forum.cern.ch/u/RNugent)\
**Post date:** [December 5, 2022, 4:38am UTC](https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635/1 "2022-12-05T04:38:53Z")

</div>

Hi, I’m trying to make a simple graph and I keep encountering the error message (along with 11 others): “TypeError: could not convert argument 2 (could not convert argument to buffer or nullptr)”. I have my code below. It is simple looking as I was trying to troubleshoot the same error I was recieving in my main code.  
 ![error code](https://root-forum.cern.ch/uploads/default/original/3X/d/c/dcb37f4245fa7789fe1768336a62ac26e069d3c3.png)

\_ROOT Version: 6.26.06  
\_Platform: Windows 11  
\_Compiler: JupyterHub

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [December 5, 2022, 5:26am UTC](https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635/2 "2022-12-05T05:26:03Z")

</div>

The TGraph constructors need arrays, but your x and y are (Python) lists. One way could be to convert them to arrays when passing them:

```auto
import ROOT
from array import array
x = [1,2,3,4,5]
y = [1,4,9,16,25]
gr = ROOT.TGraph(5,array("i",x),array("i",y))

```

Probably there are other/better ways, though 🙂

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 5, 2022, 8:21am UTC](https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635/3 "2022-12-05T08:21:46Z")

</div>

In C++ that will be:

```auto
{
   double x[5] = {1,2,3,4,5};
   double y[5] = {1,4,9,16,25};
   auto g = new TGraph(5,x,y);
   g->Draw();
}

```

 ![Screenshot 2022-12-05 at 09.21.22](https://root-forum.cern.ch/uploads/default/original/3X/6/b/6bdbdcc403aefd11cdd566f55ec768da26c0848e.png)

---

<div class="post-metadata">

**Author:** ![RNugent](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/53a042/32.png) [@RNugent](https://root-forum.cern.ch/u/RNugent)\
**Post date:** [December 9, 2022, 12:37am UTC](https://root-forum.cern.ch/t/tgraph-not-working-returning-error-message-could-not-convert-argument-to-buffer-or-nullptr/52635/4 "2022-12-09T00:37:01Z")

</div>

Thank you so much, solved the problem immediately!
