# Coloured scatterplot from TDataFrame

**URL:** <https://root-forum.cern.ch/t/coloured-scatterplot-from-tdataframe/26894>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [November 13, 2017, 9:23pm UTC](https://root-forum.cern.ch/t/coloured-scatterplot-from-tdataframe/26894 "2017-11-13T21:23:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 13, 2017, 11:14pm UTC](https://root-forum.cern.ch/t/coloured-scatterplot-from-tdataframe/26894/2 "2017-11-13T23:14:17Z")

</div>

Hi garjola,  
scatterplots in ROOT are provided by [TGraph](https://root.cern.ch/doc/v608/classTGraph.html). `TTree::Draw` is a handy feature to quickly produce histograms and TGraphs from trees. TDataFrame does not provide a specific action to produce TGraphs, but you can always use [Foreach](https://root.cern/doc/master/classROOT_1_1Experimental_1_1TDF_1_1TInterface.html#a4b1e56639cc4c79cb9d689faf1b11984):

```auto
TGraph g;
auto fillGraph = [&g](double x, double y) { g.SetPoint(g.GetN(), x, y); };
tdf.Foreach(fillGraph, {"x", "y"});

```

I hope this helps you doing what you want.

As a side note, in the example code that you linked each `TTree::Draw` call makes a separate loop over all data – if you fill multiple `TGraph`s in the same `Foreach` lambda, TDataFrame loops over data once and fills everything saving you some runtime.

Cheers,  
Enrico

---

_[View the full topic](https://root-forum.cern.ch/t/coloured-scatterplot-from-tdataframe/26894)._
