Hatching - how to keep same spacing between lines

I am using the hatched area (style 3144) to represent the represent the errors.
And I want to have the same spaces between lines in two pads of different size.
By default, they are not.
I’ve tried gStyle->SetHatchesSpacing but it doesn’t work for me.

The code is the following:

    gStyle->SetOptStat(0);
    gStyle->SetHatchesSpacing(16);

    TCanvas *can = new TCanvas("can","can", 1000, 400);

    TPad *pad1 = new TPad("pad1","p1", 0, 0, 0.2, 1);
    TPad *pad2 = new TPad("pad2","p2", 0.2, 0.0, 1, 1);
    pad2->SetRightMargin(0.7);
    pad1->Draw();
    pad2->Draw();

    TH1D *h[2];
    for(int i = 0; i < 2; ++i) {
        h[i] = new TH1D(TString::Format("h%d",i), "", 1, -5, 5);
        h[i]->SetBinContent(1, 1);
        h[i]->SetBinError(1, 0.4);
        h[i]->SetFillColor(kOrange);
        h[i]->SetFillStyle(3144);
        h[i]->GetXaxis()->SetLabelFont(43);
        h[i]->GetYaxis()->SetLabelFont(43);
        h[i]->GetXaxis()->SetLabelSize(10);
        h[i]->GetYaxis()->SetLabelSize(10);
    }

    pad1->cd();
    h[0]->Draw("e2");

    pad2->cd();
    h[1]->Draw("e2");

The result looks like this and I want to have the same hatching style in both frames.

The hatches greater than 3025 are in fact not fill patterns but lines drawn by ROOT graphics.That’s why you can change spacing and line width. It may well be that some effects similar to what you describe can appear. This would require a closer look to see why… To make sure you have invariant hatching choose the pattern in the top 25 ones shown on this table.

Thanks,
FillStyle 3013 it really makes the hatching same in both frames.

The bad thing is that with using this style I can’t control the line width and spacing between lines as the methods

gStyle->SetHatchesSpacing
gStyle->SetHatchesLineWidth

have no effect…

Yes this fixed pattern cannot be changed. I will try to see if something can be done to fix the issue you see with hatches greater than 3025.

indeed the line spacing depends on the pad size because these pattern are drawn using normal line. You can see the same effect if you grow and shrink the canvas. The line spacing adjust according to the canvas size. That something special to these patterns and might be useful in some cases.

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