Incorrect bin value and palette range display in TGraph2D and 2D Histogram when using CONT4Z

Dear Rooters,

I’m trying to display an ROC curve in 2D using CONT4Z. I use as input data from an ascii file (x,y,z). TGraph2D and TH2F both display incorrect palette range and bin values. Altering the bin size does not solve the problem.

Any help would be appreciated.

For input file see sample.txt (9.0 KB)

For script see:

#include "Riostream.h"

void Sample_2() {
gStyle->SetOptStat(0);
gStyle->SetPalette(1);

   ifstream in;
   in.open("sample.dat");

// First use TGraph2D constructor to see what plot looks like:
   TCanvas *c1 = new TCanvas("c1"," ",0,0,700,350);
   c1->SetFrameFillColor(TColor::GetColorPalette(0));
   c1->SetFrameFillColor(4);
   c1->Divide(2,1);
   c1->cd(1);
   TGraph2D *g1 = new TGraph2D("sample.dat");
   g1->Draw("cont4z");

// Next repeat process by reading in ascii file into 2D histo and plotting
   c1->cd(2);
   Float_t x,y,z;
   Int_t nlines = 0;

   TH2F *h2 = new TH2F("h2","Same data but using 2DHisto",40,0,1,40,0,1);

   while (1) {
      in >> x >> y >> z;
      if (!in.good()) break;
      h2->Fill(x,y,z);
      nlines++;
   }
   in.close();
   h2->SetContour(10);
   h2->SetMinimum(150);
   h2->SetMaximum(250);
   h2->Draw("CONT4Z");
   c1->Update();
}

For script output see

The plot on the left is generated with TGraph2D. It is totally wrong, the Z scale and the interpolation between points. The plot on the right is better but also wrong. Z ranges from 160 to 215 (see attached text file) and increases as one moves towards the top right of the plot. Also, is there a way to set bins with value below a cut-off to be white, for example bins with values < 160 == white?

many thanks in advance

I guess the problem is that, in your “sample.dat” file, almost all pairs “x”, “y” have multiple (up to 6) values for “z”.
Try:

{
  TTree *t = new TTree("t", "t");
  t->ReadFile("sample.txt", "x:y:z");
  t->Draw("z:y:x:z");
}

Hi,

The problem isn’t the precision of the variables x or y. It was originally to 3 decimals but I rounded it to 2 decimals to see if it would make a difference. It doesn’t.

Your suggestion gives me a plot in 3D. I don’t want a 3D plot, I want a 2D plot projected in Z, i.e. what you get when using the CONTZ option.

thanks.

You do not have enough “x”, “y” pairs to “fill” a 2-dimensional plane (your points form a single 3-dimensional line).
Try:

{
  TTree *t = new TTree("t", "t");
  t->ReadFile("sample.txt", "x:y:z");
  t->SetMarkerStyle(20); // t->SetMarkerSize(0.5);
  t->Draw("y:x:z", "", "colz");
}

Great! Your suggestion works just fine.
Thanks.

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