TH2Poly SetLineColor etc. has no effect

sorry, perhaps a totally stupid question, but I am stuck…
I have a TH2Poly and want to style the appearance of the bin borders (line color, line style, line width, etc…). None of the methods I am trying has the desired effect. What am I doing wrong? How can I achieve the desired behavior?

void plotPixelPlane(){
        TFile *f = new TFile("FOCALPixelPlane.root", "READ");
        TH2Poly *p = (TH2Poly*) f->Get("h2polyFOCALPixelPlane");
        TCanvas *c = new TCanvas("c","c",600,600);

FOCALPixelPlane.root (126.0 KB)
plotPixelPlane.C (295 Bytes)

Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.


ROOT v6.30/01
Built for linuxx8664gcc on Mar 05 2024, 02:22:43
From tags/v6-30-01-alice3@v6-25-02-6401-g65d7dbc65f
With c++ (GCC) 12.2.0
Binary directory: /home/mxr/dev/cern/alice/sw/ubuntu2204_x86-64/ROOT/v6-30-01-alice3-1/bin


Hi and welcome on the forum,

Try with root --web plotPixelPlane.C. This will use web-based rendering - which works as expected:

To get result with normal graphics, you need to change attributes of individual TH2PolyBin:

   TIter iter(p->GetBins());
   while(auto bin = (TH2PolyBin *) iter()) {
      TGraph *gr = (TGraph *) bin->GetPolygon();

Thanks a lot! This helped.

I’ll check the normal root

Actually this does not fly because on can set the color individually for each bin when you add them in the TH2Poly.

Hi Olivier,

Please check why line width / line style for individual graphs are ignored.
After my modifications in the macro I see:

My macro:
plotPixelPlane.C (501 Bytes)


Yes I see that line width/style are ignored. I ll provide a fix. but you cannot set a global color like in the original example. Your version is correct. Only It requires a fix. The way web graphics behave is wrong.

I will wait your fix and then sync with JSROOT

1 Like

Ah, yes, didn’t notice, but also for me width and style methods are ignored. Line color works, which is for the moment sufficient for my application. Thanks again.

I am on it … gime some times

This PR fixes the problem Make sure the option L draws closed polygon for TH2Poly by couet · Pull Request #14975 · root-project/root · GitHub

Thanks to have seen it.

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