Transparent pad in PNG is not transparent in PDF

Hi,

I’m trying to make a plot with two pads, one for the actual histograms and one for the data/mc ratio. When plot in linear scale, the “0” of the top-pad is cropped by the ratio pad unless the latter is filled as transparent (obtained with SetFillStyle(0) and SetFillColor(0)). My code is below. However, this trick seems to work fine when I save the canvas in PNG format, but not in PDF! I’m using ROOT 5.34/19.

Thank you in advance,
Riccardo

def MakeCanvas( npads = 1, side = 800, split = 0.25, padding = 0.00 ):
   # assume that if pads=1 => square plot
   # padding used to be 0.05
   y_plot    = side * ( 1. - ( split + padding ) )
   y_ratio   = side * split
   y_padding = side * padding

   height_tot = y_plot + npads * ( y_ratio + y_padding )
   height_tot = int(height_tot)

   c = TCanvas( "PredictionData", "Prediction/Data", side, height_tot )

   pad0 = TPad( "pad0","pad0",0, split+padding,1,1,0,0,0 )
   pad0.SetLeftMargin( 0.16 )
   pad0.SetRightMargin( 0.05 )
   pad0.SetBottomMargin( 0. )
   #pad0.SetTopMargin( 0.14 )
   pad0.SetTopMargin( 0.05 )
   pad0.Draw()

   pad1 = TPad( "pad1","pad1",0,0,1, split,0,0,0 )
   pad1.SetLeftMargin( 0.16 )
   pad1.SetRightMargin( 0.05 )
   pad1.SetTopMargin( 0. )
   pad1.SetBottomMargin( 0. )
   pad1.SetGridy(1)
   pad1.SetTopMargin(0)
   pad1.SetBottomMargin(0.4)
   pad1.Draw()
   # ninja hack not to crop the “0”
   pad1.SetFillColor(0) 
   pad1.SetFillStyle(0)

   pad0.cd()
   return c, pad0, pad1

Your macro converted in C++ gives me ( on Mac, with ROOT 6.04) the same output with png and pdf: a white page.

void transpadpdf( int npads = 1, int side = 800, float split = 0.25, float padding = 0.00 )
{
   float y_plot    = side * ( 1. - ( split + padding ) );
   float y_ratio   = side * split;
   float y_padding = side * padding;

   float height_tot = y_plot + npads * ( y_ratio + y_padding );
   height_tot = int(height_tot);

   TCanvas c( "PredictionData", "Prediction/Data", side, height_tot );

   TPad pad0( "pad0","pad0",0, split+padding,1,1,0,0,0 );
   pad0.SetLeftMargin( 0.16 );
   pad0.SetRightMargin( 0.05 );
   pad0.SetBottomMargin( 0. );
   pad0.SetTopMargin( 0.05 );
   pad0.Draw();

   TPad pad1( "pad1","pad1",0,0,1, split,0,0,0 );
   pad1.SetLeftMargin( 0.16 );
   pad1.SetRightMargin( 0.05 );
   pad1.SetTopMargin( 0. );
   pad1.SetBottomMargin( 0. );
   pad1.SetGridy(1);
   pad1.SetTopMargin(0);
   pad1.SetBottomMargin(0.4);
   pad1.Draw();
   pad1.SetFillColor(0);
   pad1.SetFillStyle(0);

   pad0.cd();
   c.Print("transpadpdf.pdf");
   c.Print("transpadpdf.png");

}