Stripes in histogram with fill

I’m making some plots in a simple macro which just takes a histogram from a file, formats it and saves it as a pdf. For some reason when I do this, my plots end up with white stripes on them when I save them, but not when I look at them in the interactive root session. Can someone tell me why and how to solve this?

I’m using ROOT 6.26.06_1 on MacOS Ventura 13.3.1.

Here’s the code:

  TCanvas *c1 = new TCanvas("c1","c1",900,700);
  TH1F* h1 = (TH1F*)_file->Get("dir/hist");
  h1->Draw("HISTO");
  h1->SetStats(0);
  h1->SetFillColor(kBlack);
  h1->SetLineColor(kBlack);
  h1->SetLineWidth(2);
  h1->SetFillStyle(3001);
  h1->SetTitle(";PVetoChID+EVetoChID;#Events");
  h1->GetYaxis()->SetTitleOffset(1.35);
  
  c1->SetRightMargin(0.025);
  c1->SetLeftMargin(0.09);
  c1->SetTopMargin(0.02);
  c1->SetBottomMargin(0.075);
  c1->SetBorderMode(1);
  c1->SetHighLightColor(0);
  c1->Modified();
  c1->Update();

  c1->Print("/Path/To/Save/Name.pdf");

This is what it looks like in the interactive session:

Whereas this is what the saved file looks like

Yes, the rendering of pattern style 1 is not good on pdf. Especially on screen. When printed it is ok. But that pattern was mainly implemented to emulate grey. You will get a better result defining a real grey color and filling your histogram with a solid color.

I’m not sure I understand - this problem happens no matter whether the histogram is filled with black, green, red or blue, and on the screen it looks fine but when printed to pdf it gets this weird effect…

Yes, the pattern number “1” is rendered in a weird way with some pdf viewers. I would not recommend using it.

  • Use a higher pattern number if you want to use pdf as output,
  • or render as png,
  • or use a grey solid color which will be a similar rendering.

Ok thank you

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