Can TGraph2D be draw with circle and circle size like below?

I want to draw like below, but I do not want to write many circle class.

what if only with circle color/size?

Hi,

There is new TScatter class which does exactly this.

https://root.cern/doc/master/classTScatter.html

But it only available in ROOT master branch and will appear only with next release.

2 Likes

Note that in the case of TScatter the circles are drawn as markers, so the circles’ radii are defined with the marker sizes. If you need to define real radii that might be a bit more complex. You will need to find the right sizes matching the radii you need.

that is an exciting news, looking for it long time ago

Can this class be auto memory calloc and clean function like
TGraph2D::SetPoint(TGraph2D::GetN(), newX, newY)
and TGraph2D::Clean?
I havn’t find the funciton yet.

It has a TGraph internally. See the Help.

founded thanks

but I found a bug on axis plotting with gPad->DrawFrame().

It is not a bug. TScatter behaves like TGraph ie: the option SAME does not exist:

void scat2()
{
   TCanvas * c1 = new TCanvas();
   gPad->DrawFrame(-70, -70, 70, 70);
   const int n = 10;
   double x[n] = {-80, -70, -60, -50, -40, -30, -20, -10, 0, 10};
   double y[n] = {-80, -70, -60, -50, -40, -30, -20, -10, 0, 10};
   double c[n] = {-80, -70, -60, -50, -40, -30, -20, -10, 0, 10};
   double s[n] = {-80, -70, -60, -50, -40, -30, -20, -10, 0, 10};
   auto scatter = new TScatter(n, x, y, c, s);
   scatter->Draw("P");
}

thanks

another problem
do I need to calculate colors by myself?

void scatter3()
{
	const int n = 18;
	double x[18] = {0,-47.25,-57.75,-54.25,-57.75,-43.75,-1.75,-43.75,-57.75,-1.75,12.25,-5.25,-33.25,-22.75,-8.75,43.75,-1.75,12.25};
	double y[18] = {-40,71.75,71.75,61.25,57.75,47.25,54.25,43.75,64.75,19.25,26.25,54.25,-8.75,-40.25,-8.75,-64.75,15.75,22.75};
	double c[18] = {1874.1, 37.3506,31.0556,34.5008,33.8461,51.9826,74.6671,80.9407,25.4095,132.617,133.999,67.8644,173.057,214.65,182.864,302.821,139.372,138.381};
	double s[18] = {3,3.17609,2.69897,3.38021,3.04139,2,2.69897,2,2.8451,2.47712,3,3.04139,2.90309,3.43136,3,3.30103,2.95424,2.30103};
	TScatter * s1 = new TScatter(n, x, y, c, s);
	s1->SetMarkerStyle(kFullCircle);
	s1->SetScale(2);
	s1->Print();
	new TCanvas();
	auto hf =  gPad->DrawFrame(-80, -80, 80, 80);
	s1->Draw("P");
	hf->GetZaxis()->SetRangeUser(0, 2000);
}

the first point with a large color number(1874.1) show wrong colors like below

I simplified your macro but still, that point stays blue. I’ll check.

void scatter3()
{
   const int n = 18;
   double x[18] = {0,-47.25,-57.75,-54.25,-57.75,-43.75,-1.75,-43.75,-57.75,-1.75,12.25,-5.25,-33.25,-22.75,-8.75,43.75,-1.75,12.25};
   double y[18] = {-40,71.75,71.75,61.25,57.75,47.25,54.25,43.75,64.75,19.25,26.25,54.25,-8.75,-40.25,-8.75,-64.75,15.75,22.75};
   double c[18] = {1874.1, 37.3506,31.0556,34.5008,33.8461,51.9826,74.6671,80.9407,25.4095,132.617,133.999,67.8644,173.057,214.65,182.864,302.821,139.372,138.381};
   double s[18] = {3,3.17609,2.69897,3.38021,3.04139,2,2.69897,2,2.8451,2.47712,3,3.04139,2.90309,3.43136,3,3.30103,2.95424,2.30103};
   TScatter * s1 = new TScatter(n, x, y, c, s);
   s1->SetMarkerStyle(kFullCircle);
   s1->Draw("AP");
}

Running root --web scatter3.C makes is better :grinning:

1 Like

Yes but I need to fix the normal root…

Of course.

Fix here: Markers at the maximum did not have the right color by couet · Pull Request #13144 · root-project/root · GitHub
Thanks to have seen it.

Dear Expert,
Is this fix available now?
Thanks.

Yes, I just merged it. It was a bit longer than expected because there was also an issue with the marker size. (see the PR).

2 Likes

thanks for your help! :hugs:

1 Like