How to set TH2F draw with SURF1 but not render by Z value

I now want to achieve surface drawing through TH2F and it has been successful, but the current color is drawn based on the content in SetBinContent. Can I set additional properties for each bin and then draw the color of the bin based on this property?

     auto c2 = new TCanvas("c2", "c2", 600, 400);
    auto hsurf3 = new TH2F("hsurf3", "Option SURF3 example ", 30, -4, 4, 30, -20, 20);
    for (Int_t i = 0; i < 30; i++) {
        for (Int_t j = 0; j < 30; j++) {
            Int_t bin = hsurf3->GetBin(j + 1, i + 1);
            hsurf3->SetBinContent(bin, i);
    UInt_t Number = 2;
    Double_t Red[2] = { 1.00, 0.00 };
    Double_t Green[2] = { 0.00, 1.00 };
    Double_t Blue[2] = { 0.00, 1.00 };
    Double_t Length[2] = { 0.00, 1.00 };
    Int_t nb = 50;
    TColor::CreateGradientColorTable(Number, Length, Red, Green, Blue, nb);


That’s is not foreseen rigth now. Any way a TH2 has only 3 variables: X Y and Z.

Thank you for your reply. Is there any feasible way for me to achieve this effect now

I am working on it. Give me time.

Thank you for your help

how is defined the plane ?

I don’t know how to define this plane. The diagram above was drawn by me using Matlab, but in fact, I only used the patch (X, Y, Z, C) function.

patch(X,Y,Z,C) creates the polygons in 3-D coordinates using X, Y, and Z. To view the polygons in a 3-D view, use the view(3) command. C determines the color.

In our root code, my idea is to add a C value similar to that in a patch (X, Y, Z, C) while setting the Z value for SetBinContent? If the C value is not set, draw the color according to the Z value. If the C value is set, draw the color according to the C value. This is my idea, I’m not sure if it’s feasible.

Ah ok. I understand. That’s more genral that I thought. There is nothing like that in ROOT right now. Sorry for that.

Okay, but does root have a plan to implement this feature?

The patch technique from MathLab no… For the idea of drawing a 4th variable as color on SURF1 why not … but the question is: where is the 4th variable coming from ? … we can sider to draw te TH2 errors as colors. The option could be SURF1E

That’s also possible. When will this feature be supported?

No idea. It is just a possibility. Nothing has been decided.and looking at it it is not trivial to do (may be not possible)… so don’t wait for it.

I just looked at the code for the ThistPainter and TPainter3dAlgorithms classes and found the following code in TPainter3dAlgorithms:: SurfaceFunction:

//The colors on the surface can represent the content or the errors
//If (fSumw2. fN) t [i]=gCurrentHist ->GetBinError (icx, iyt+iya);
//Else t [i]=f [i * 3+3];
T [i]=f [i * 3+3];

I feel that by releasing the code comments, it is possible to draw the color of surf1 according to error。Is my idea correct?

That’s not enough to uncomment that. The palette is not right and the colors are used in increasing order of Z . That’s not what is needed.

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