Problem plotting 2D graphs with log scales x, y ,z

Dear root’ers
I’ve been having some issues potting 2d graphs with log axis on x, y and z. If I plot the data as a ‘COLZ’ I can see the entire scale with all my data available. However, if I plot the same data with the ‘SURF1’ option a significant part of my data is missing from the graphs!?

Is there a reason for this and can I find a ‘work around’ its super frustrating right now. Here is the snippet of code for the drawing:

TCanvas *CFWHM = new TCanvas("FWHM", "FWHM", 600, 600, 600, 600);
CFWHM->Divide(2); 

gStyle->SetPalette(1);
CFWHM->cd(1);
gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
Dt->G2d_FWHM->Draw("COLZ");
CFWHM->cd(2);
gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
Dt->G2d_FWHM->Draw("SURF1");gPad->Update();

And here is the output :
image


ROOT Version: 6.14.02
Platform: Visual studio 17
Compiler: VS 10.0.17134.0


It seems to me that the problem is that the “SURFace” drawing option paints the plot between the middles / centres of bins (and so the areas between the low-edge of the first bin and its middle / centre and then between the middle / centre of the last bin and its upper-edge are left “blank”).
The “COLor” drawing option paints entire / whole bins.

Thanks for the quick reply, I did a quick check to see if the binning is the problem here… but it doesn’t appear to be the case. The plot to the left is the “PCOL” option and the right the “surf” option. Its pretty clear that the graph to the right is missing data points :frowning: . Any suggestions?

I changed the fill part of the code to
for(…){
h2->Fill(x,y,1.0)
}
Thanks in advance
StuPid1
image

can you post a macro reproducing the problem ?

ok, give me a few min. i have to isolate it from the code

void HistyIssue() {
	vector<double> Xvals{ 1,10,100,1000,10000,1e5,1e6,1e7,1e8 };
	vector<double> Yvals{ 1,10,100,1000,10000,1e5,1e6,1e7,1e8 };
	

	int dtpoints = (int)(Xvals.size()*Yvals.size());
	TH2F* test = new TH2F("test", "test", Xvals.size() - 1, &(Xvals[0]), Yvals.size() - 1, &(Yvals[0]));

	double* X = new double[dtpoints];
	double* Y = new double[dtpoints];
	double* Z = new double[dtpoints];

	for (int i = 0; i < (int)Xvals.size(); i++) {
		for (int j=0; j < (int)Yvals.size(); j++)	{
			//fill hist 
			test->Fill(Xvals[i], Yvals[j], 1.0);

			// for the tgraph 
			int itt = i * (int)Xvals.size() + j;
			X[itt] = Xvals[i];
			Y[itt] = Yvals[j];
			Z[itt] = TMath::Power(10,i);
		}
	}

	TCanvas* C1 = new TCanvas(); 
	C1->Divide(4);
	
	//hist 
	C1->cd(1); 
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	test->SetMarkerSize(1);
	test->SetMarkerStyle(20);
	test->Draw("Pcol");

	C1->cd(2);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	test->Draw("Surf1");


	//another proof of madness 
	TGraph2D* g2 = new TGraph2D("g2", "g2", dtpoints, X, Y, Z);
	C1->cd(3);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	g2->SetMarkerSize(1);
	g2->SetMarkerStyle(20);
	g2->Draw("Pcol");

	C1->cd(4);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	test->Draw("Surf1");
	
}

so this appears to work just fine, give the output shown below:

i will continue to look into it but its clearly a problem in my code.
thanks for the help guys
stu

Check the “x-” and “y-” axis low-edges of the first bin of your histograms. If any is less than or equal to 0, this bin may be skipped when drawing.

So I decided to investigate further and found this happens with the graph……

from this code

{
void HistyIssue() {
	vector<double> Xvals{ 1,10,100,1000,10000,1e5,1e6,1e7,1e8 };
	vector<double> Yvals{ 1,10,100,1000,10000,1e5,1e6,1e7,1e8 };
	int dtpoints = (int)(Xvals.size()*Yvals.size());
	TH2F* test = new TH2F("test", "test", Xvals.size() - 1, &(Xvals[0]), Yvals.size() - 1, &(Yvals[0]));

	double* X = new double[dtpoints];
	double* Y = new double[dtpoints];
	double* Z = new double[dtpoints];

	for (int i = 0; i < (int)Xvals.size(); i++) {
		for (int j=0; j < (int)Yvals.size(); j++)	{
			// for the tgraph 
			int itt = i * (int)Xvals.size() + j;
			X[itt] = Xvals[i];
			Y[itt] = Yvals[j];
			Z[itt] = TMath::Power(10,i);
			//fill hist 
			test->Fill(Xvals[i], Yvals[j], Z[itt]);
		}
	}

	TCanvas* C1 = new TCanvas(); 
	C1->Divide(4);
	
	//hist 
	C1->cd(1); 
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	test->SetMarkerSize(1);
	test->SetMarkerStyle(20);
	test->Draw("Pcol");

	C1->cd(2);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	test->Draw("Surf1");


	//another proof of madness 
	TGraph2D* g2 = new TGraph2D("g2", "g2", dtpoints-1, X, Y, Z);
	C1->cd(3);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	g2->SetMarkerSize(1);
	g2->SetMarkerStyle(20);
	g2->Draw("Pcol");

	C1->cd(4);
	gPad->SetLogx();	gPad->SetLogy();	gPad->SetLogz();
	g2->Draw("Surf1");
	
}
}

does the ‘surf’ option do some sort of averaging over and area?

The SURF option used on a TGraph2D makes an interpolation via the Delaunay triangulation to fill a 2D histogram. It seems in that case the triangulation gets lost . If you plot the TGraph2D with the option TRI, showing the triangles used, you will get the following plot. It seems there is something wrong with the data.

Thanks for the information, i did the same “tri” option and i get the same as you. However, if you plot both tri on one canvas and the ‘SURF’ on the other you get the mess that i have in a prior comment.

thanks for that though, i can at least us it to validate the rest of my data.

cheers

stu

Yes you can inspect your data using the TRI option. The triangles shown will be those used to fill the underlying histogram. Note also that a TGraph2D assumes that for one (x,y) pair there is only one z value. I also tried to plot your TGraph2D without the log option sand I also get a messed up plot.

Hi,
I am afraid this is an issue with the TRI algorithm when
points happen to fall on straight lines in some direction
of the surface.
This can be shown if one moves the Z-values a bit

Z[itt] = TMath::Power(10,i);
// shake it a bit
Z[itt] += 0.001 * (gRandom->Rndm() - .5);

After this for me the TRI plot looks ok

Cheers
Otto

Thanks Otto for the additional information.
I will just have to use a histogram in the mean time, will this be reported as a BUG?

cheers

Stupid1

Yes there is a problem with the dotted lines it seems when points are aligned.
I can reproduce with:

{
   auto g = new TGraph2D();
   g->SetPoint(0,1.,1.,1.);
   g->SetPoint(1,2.,1.,2.);
   g->SetPoint(2,3.,1.,3.);
   g->SetPoint(3,1.,2.,1.);
   g->SetPoint(4,2.,2.,2.);
   g->SetPoint(5,3.,2.,3.);
   g->Draw("TRI FB BB P0");
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.