# Scatter plot with radius

**URL:** <https://root-forum.cern.ch/t/scatter-plot-with-radius/51990>\
**Category:** Newbie\
**Tags:** root\
**Created:** [October 16, 2022, 9:22pm UTC](https://root-forum.cern.ch/t/scatter-plot-with-radius/51990 "2022-10-16T21:22:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [October 16, 2022, 9:22pm UTC](https://root-forum.cern.ch/t/scatter-plot-with-radius/51990/1 "2022-10-16T21:22:22Z")

</div>

I am trying to produce 2D scatter plot with 3 variable set x-coordinate, y-coordinate and radius of the event or circle. I am not sure how to add radius to the Scatter plot. Is there any way possible to plot these data?  
I am trying to produce similar plot as below, I produced using python,  
 ![2D hist](https://root-forum.cern.ch/uploads/default/original/3X/4/6/466330d73e742c6b94b8e432863e772096c32591.jpeg)

Appreciate the help.

---

<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:** [October 17, 2022, 5:00am UTC](https://root-forum.cern.ch/t/scatter-plot-with-radius/51990/2 "2022-10-17T05:00:21Z")

</div>

I don’t think there’s an option to automatically have markers proportional to the “value” (except with “boxes”, see below); you could set by hand a marker size (proportional to the radius) for every point, but for this you need one TGraph for each point (or at least for each radius size), so it’s not practical when you have many points.  
With ROOT you can have boxes bt drawing a 2D histogram with the “[box](https://root.cern/doc/master/classTHistPainter.html#HP13)” option; you make a TH2D histogram and fill it with SetBinContent, e.g. `h->SetBinContent(binx,biny,radius)` and when drawn, the boxes are proportional to the radius; however, in your plot it seems that many circles are overlapping, and this will not look like that in ROOT, as each box will be constrained to its bin size.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [October 17, 2022, 9:40am UTC](https://root-forum.cern.ch/t/scatter-plot-with-radius/51990/3 "2022-10-17T09:40:31Z")

</div>

This visualization _as a scatter plot_ isn’t working well for HEP: how do you determine the circles’ center, how many neighboring points are combined, and how many circles are occluded?

I would assume that this is actually a graph, with precise X and Y positions, and a value (Z) at that point. This can be done with a `TGraph2D`.

If you are indeed plotting a 2D histogram (“scatter plot” seems to suggest that) then the BOX option sounds like a superior visualization.

---

<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:** [October 25, 2022, 1:24pm UTC](https://root-forum.cern.ch/t/scatter-plot-with-radius/51990/4 "2022-10-25T13:24:44Z")

</div>

Actually, the option BOX will work for binned data (TH2). I am not sure your data are binned. At least it is not obvious from the plot you posted.  
I made a prototype of real scatter plots (not yet in the ROOT code) which might be more useful in your case. The macro code looks like this:

```auto
/// \file
/// \ingroup tutorial_graphs
/// \notebook
/// Draw a scatter plot.
///
/// \macro_image
/// \macro_code
///
/// \author Olivier Couet

void scatter()
{
   auto canvas = new TCanvas();
   gStyle->SetPalette(kRainBow, 0, 0.5); // define a transparent palette

   const int n = 100;
   double x[n];
   double y[n];
   double c[n];
   double s[n];

   // Define four random data set
   auto r = new TRandom();
   for (int i=0; i<n; i++) {
      x[i] = 100*r->Rndm(i);
      y[i] = 200*r->Rndm(i);
      c[i] = 300*r->Rndm(i);
      s[i] = 400*r->Rndm(i);
   }

   auto scat = new TScatter(n, x, y,c,s);
   scat->SetMarkerStyle(20);
   scat->SetMarkerColor(kRed);
   scat->SetTitle("Scatter plot;X;Y");
   scat->Draw("A");
}

```

And the plot we get is:

 ![Screenshot 2022-10-25 at 15.21.21](https://root-forum.cern.ch/uploads/default/original/3X/f/f/ffeb6d9ddd0f0ac9b9078241e84967c00c73bb46.png)
