Unbinned 3-d scatter-plot

I am trying to use the “TTree::Draw” to produce an unbinned 3-d scatter-plot: { gStyle->SetPalette(-1); // index 40->49 : basic colors TNtuple *n = new TNtuple("n", "n", "x:y:z:color"); for (Int_t i = 0; i < 100000; i++) { Float_t x, y, z, color; gRandom->Rannor(x, y); z = x*x + y*y; if (z > 2.0) continue; // skip "too big" values color = TMath::Ceil(4.0 * z + 0.5); // "basic colors" 1 ... 9 n->Fill(x, y, z, color); } n->Draw("x:y:z:(50 - color)"); } I’ve got two problems:

  1. the colors that I get do NOT correspond to what I expect (well, I expect “basic colors” … 1 / “black”, 2 / “red”, 3 / “green”, …, 9 / “dark blue” to appear).
  2. I would like to define my own “frame” … for example, I would like to have axes " -2 < x < 2", “-3 < y < 3”, “-1 < z < 3” (well, I’d like to share the same “frame” between several such canvases / pads) -> how can I do this?
    Thanks in advance,
    Best regards,
    Wile E.

Yes, that’s the default ugly palette … that’s correct. This palette is defined as:

Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
21,22,23,24,25,26,27,28,29,30, 8,
31,32,33,34,35,36,37,38,39,40, 9,
41,42,43,44,45,47,48,49,46,50, 2,
7, 6, 5, 4, 3, 2,1}

define your own palette to control the colors.

Note that I do try to use the last 9 colors of this palette but I do NOT get them in the picture (try to run my example macro -> at least the last 7 colors should be o.k. -> “7, 6, 5, 4, 3, 2,1” and instead of “8” I should get “2” while instead of “9” I should get “50”).

How about my question “2.”?

That’s not how it works. The variable “color” in not the color index of the color. A mapping between color-min and color-max is done on the color map like when you plot and histogram with option colz.

Can anybody recommend any solution to the following problem …

I have several ntuples of “x:y:z:color”.
Each ntuple has somehow different ranges of “x”, “y”, “z” and “color”.
I would like to draw every ntuple in a separate canvas (or pad) as “unbinned 3-d scatter-plot”, for example using something like: ntuple->Draw(“x:y:z:color”);
However, all canvases (pads) should get exactly the same axes ranges (even though each ntuple has different “x”, “y” and “z” ranges) and the “color” value mapping to the palette colors should be exactly the same (even though each ntuple has different “color” minimum and maximum).

In the meantime, I have tried the following solution, but I get all points “dark green” (color number 8, I guess), which seems to be a bug in ROOT to me (related to the “same” drawing option): [code]{
// create and set a “custom” color palette
const Int_t ncolors = 16;
Int_t colors[ncolors];
for (Int_t i = 0; i < ncolors; i++) colors[i] = gStyle->GetPadColor();
for (Int_t i = 1; i < 10; i++) colors[i] = i; // “basic colors” 1 … 9
gStyle->SetPalette(ncolors, colors);

// create and draw a “dummy” ntuple (axes and the color palette “scale”)
TNtuple *n0 = new TNtuple(“n0”, “n0”, “x:y:z:color”);
n0->Fill(-1.6, -1.6, -0.1, 0); // x_min, y_min, z_min, color_min
n0->Fill( 1.6, 1.6, 2.4, (ncolors - 1)); // x_max, y_max, z_max, color_max
n0->Draw(“x:y:z:color”);

// create and draw the “real data” ntuple
TNtuple n = new TNtuple(“n”, “n”, “x:y:z:color”);
for (Int_t i = 0; i < 100000; i++) {
Float_t x, y, z, color;
gRandom->Rannor(x, y);
z = x
x + y*y;
if (z > 2.25) continue; // skip “too big” values
color = TMath::Ceil(4.0 * z); // “basic colors” 1 … 9
n->Fill(x, y, z, color);
}
n->Draw(“x:y:z:color”, “”, “same”);
}[/code]