# Plotting equation and datapoints on same graph

**URL:** <https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187>\
**Category:** Newbie\
**Created:** [November 9, 2020, 6:36pm UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187 "2020-11-09T18:36:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [November 9, 2020, 6:36pm UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187/1 "2020-11-09T18:36:56Z")

</div>

_ROOT Version:_ 6.22  
_Platform:_ Root  
Compiler: Root compiler

* * *

I want to plot the cylinder of equation x^2+y^2 = 25 and some data points(for example: 500 sample points with values of x,y,z) in a same 3D graph using TMultiGraph. But it giving the error like:

> /home/subhrod/root/macros/cylinder.C:6:6: error: no matching member function for call to ‘Add’  
> f-\>Add(f1);  
> /home/subhrod/root/include/TMultiGraph.h:53:22: note: candidate function not viable: no known conversion from ‘TF3 \*’ to ‘TGraph \*’ for 1st argument  
> virtual void Add(TGraph \*graph, Option\_t \*chopt=“”);

How do I resolve this problem?  
With regards.

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [November 9, 2020, 9:26pm UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187/2 "2020-11-09T21:26:26Z")

</div>

In order to draw both the cylinder and the data points, you can call `Draw()` on the function object and on a `TGraph` object. The second call should use the option `same`, like `Draw("same")`, in order to reuse the canvas.

---

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [November 10, 2020, 3:55am UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187/3 "2020-11-10T03:55:10Z")

</div>

Hi,  
That command will overlap both of the graph in one canvas. But I want to plot the curves in same graph so that I can visualise it on 3D, which is not possible by “same” method

---

<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:** [November 10, 2020, 5:16am UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187/4 "2020-11-10T05:16:42Z")

</div>

TMultiGraph does not accept TF3, as the error says; it only accepts Graphs (or other TMultiGraphs), see its constructors in the [documentation](https://root.cern/doc/master/classTMultiGraph.html). Maybe you can create the graphs as [TGraph2D](https://root.cern/doc/master/classTGraph2D.html) and use “same”, as there is no TMultiGraph2D.

---

<div class="post-metadata">

**Author:** ![dsubhro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dsubhro/32/24279_2.png) [@dsubhro](https://root-forum.cern.ch/u/dsubhro)\
**Post date:** [November 13, 2020, 8:52am UTC](https://root-forum.cern.ch/t/plotting-equation-and-datapoints-on-same-graph/42187/5 "2020-11-13T08:52:45Z")

</div>

Thank you.  
I have solved the problem by generating datapoints and use TGraph.
