How to change tooltip when using THttpServer

When I use THttpServer to show our histogram, I want to reverse the yaxis. But I still hope that the data can be reversed at the same time. How should we do?

My code is here:

void ReverseXAxis(TH1 *h)
{
   // Remove the current axis
   h->GetXaxis()->SetLabelOffset(999);
   h->GetXaxis()->SetTickLength(0);
 
   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                h->GetXaxis()->GetXmin(),
                                h->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}
 
void ReverseYAxis(TH1 *h)
{
   // Remove the current axis
   h->GetYaxis()->SetLabelOffset(999);
   h->GetYaxis()->SetTickLength(0);
 
   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
                                gPad->GetUymax(),
                                gPad->GetUxmin()-0.001,
                                gPad->GetUymin(),
                                h->GetYaxis()->GetXmin(),
                                h->GetYaxis()->GetXmax(),
                                510,"+");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}
int main()
{
    gStyle->SetOptStat(0);

    TH2F *hpxpy  = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
    TCanvas *c1 = new TCanvas("c1");

    THttpServer *serv = new THttpServer("http:6666");
    serv->Register("/", c1);
    serv->SetItemField("/","_monitoring","1000");
    while(1)
    {
        gSystem->ProcessEvents();
        // gettimeofday(&current_time, NULL);
        
        {  
            c1->cd(1);
            hpxpy->Reset();
            Float_t px, py;
            TRandom r;
            for (Int_t i = 0; i < 25000; i++) {
                r.Rannor(px,py);
                hpxpy->Fill(px,py);
            }
            hpxpy->Draw("colz");
            ReverseXAxis(hpxpy);
            ReverseYAxis(hpxpy);
        }
        
    }
    return 0;
}

ROOT Version: 6.24/06
Platform: Centos7.9
Compiler: gcc8


Hi,

You do not need to use TGaxis for display of reversed axes.
JSROOT which is used for drawing of histograms by THttpServer, just natively supports
reverse axis by “rx_ry” draw option:

Tooltips will work properly then.

Regards,
Sergey

1 Like

Also it is not necessary to call hpxpy->Draw("colz"); in the loop.
Once histogram drawn on the canvas - it can be used by THttpServer.
And one just need to fill that histogram.

1 Like

Thank you. I got it.
I hava another question. If I want to show the histogram in Gray Scale Imag when using TH2F. How should I do?
Such as the following picture in python.

Hi,

You can select palete code for color drawing in the options like “col_pal52”. Code for grey color palete is 52.

Of course, you can combine all options together: “col_rx_ry_pal52”

Regards,
Sergey

Here is list of colors palette implemented in the ROOT:

https://root.cern/doc/master/classTColor.html#C05

Thank you very much. I got it.

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