Marker/Line size when canvas is saved as pdf file

Hello dear ROOT experts,

I have a problem with the size of markers and line when I save several canvas as pdf files :

I have two kind of canvas :

  • one with only one pad
  • one with three different pads

Pad sizes are the same every time and canvas are created according to the size of pads, that means in the first case canvas has the same size as its pad and in the second case canvas is 3 time larger than one pad.

Interactively, markers and lines have the same width/size. However, when it is saved as a pdf, markers and lines are smaller when there is only one pad plotted in the canvas. The print function gives me the same issue.
On png files markers has the good size, but eps looks like pdf.

Is there a solution to have the same marker/line size on the two canvas saved as pdf ?

Thank you by advance

ThreePads.pdf (24.1 KB)
OnePad.pdf (16.3 KB)

I see that the pdf files you sent have been created with:

ROOT Version 5.24/00

That’s an old version and several improvements have been done in that area (pdf and markers) since then.
Try the latest ROOT version and let me know.

Thank for this information, it helps a little.

However, there are still effects. Now marker is smaller in the canvas containing three pads. Lines are bigger in the alone pad but again smaller than in the three pads.

Thanks by advance
ThreePads.pdf (24.1 KB)
OnePad.pdf (16.6 KB)

For me it looks fine. The line width is defined in pixels. I printed the two plots on paper and checked by transparency: the width is the same for both files.

1 Like

Hi Olivier,

To get the same marker size in gif and pdf, I had to modify the TPDF::DrawPolyMarker() methods:

if (fMarkerStyle == 1) { msize = 1. ; } else if (fMarkerStyle == 6) { msize = 1. ; /// instead of 1.5 } else if (fMarkerStyle == 7) { msize = 1.5 ; /// instead of 3. } else { ... }In case it depends on the system/environment one works on, could you please add a new TStyle command, e.g. gStyle->SetMarkerScalePDF(markerstyle,markersize). Note I just found a difference for markerstyle=7.


Yes… do you have a small macro showing that differences in marker sizes ?

Here’s one:Double_t x[]={1.,2.,3.,4.,5.} ; Double_t y[]={4.,7.,1.,2.,5.} ; TGraph * graph = new TGraph (5,x,y) ; graph->SetMarkerColor(kRed) ; graph->SetMarkerStyle(7) ; TCanvas * canvas = new TCanvas ("canvas") ; graph->Draw("a,p,l") ; canvas->SaveAs("ztest.gif") ; canvas->SaveAs("ztest.pdf") ; Thanks Olivier,

I do not see an difference in size.
marker 7 is supposed to be a big point
On screen (and gif) it is done using pixels (looks like a square when zoomed)
On PS and Pdf it is drawn using a circle.
That is the only difference I see. For me the size looks ok.

For me it doesn’t :frowning:
See the attached pics (gif=screen).
So I think the best way is to let the user choose…
ztest.pdf (13.3 KB)

Hi Mathieu
I have applied your patch in the trunk (TPDF).
I agree, with the factors you suggested, it is may be a bit better.
For me it does not make a big difference. But you surely have better eyes than me.
Anyway your patch is in.

Thanks Olivier :wink:
See you,

Similarly, the following parameters seem better to me:

gStyle->SetLineStyleString(2,"8 8") ; gStyle->SetLineStyleString(3,"4 5") ; gStyle->SetLineStyleString(4,"10 10 4 10") ; /// size=3 appears as a very tiny point :-( gStyle->SetLineStyleString(5,"16 12 4 12") ; /// not very faithfull but different enough from ls=4 gStyle->SetLineStyleString(6,"16 8 4 8 4 8 4 8") ; gStyle->SetLineStyleString(7,"16 16") ; /// 12 12 would be more faithfull but no enough different from ls=2 gStyle->SetLineStyleString(8,"16 8 4 8 4 8") ; gStyle->SetLineStyleString(9,"45 15") ; although not perfect (see comments)


Where should that go ?
can you send a patch file ?
Would be simpler to apply.

It should go in core/base/src/TStyle.cxx (diff file against the trunk attached below)

  • other values are used in tmva/test/mvaeffs.C and tmva/test/tmvaglob.C
  • the user still has the possibility to define her/his own parameters in her/his rootlogon.C

PS: One style was missing: gStyle->SetLineStyleString(10,“47 23 4 23”) ;
TStyle.cxx.diff (1.39 KB)

Hi Mathieu,

I tested your changes with stressGraphics. It reports an erreur in test #1 (the test about line style).
I looked more closely in the outputs this test gives (without your changes). Seems to me all the files (various formats) are very similar without your changes. So I am not sure your changes are an improvement.


[quote]I tested your changes with stressGraphics. It reports an erreur in test #1 (the test about line style)[/quote]I can reproduce that too. I don’t really understand the filesize test but if one changes the values of GIFRef# and/or GIFErr# in line 1 of stressGraphics.ref, it goes fine.

[quote]I looked more closely in the outputs this test gives (without your changes). Seems to me all the files (various formats) are very similar without your changes. So I am not sure your changes are an improvement.[/quote]I find the discrepancy: the canvas size (see macro below). If one uses the canvas default size, gif/png and pdf files look quite similar indeed (compare histo_default_canvas.gif and histo_default_canvas.pdf). If one uses another size for the canvas, differences become obvious (compare histo_maximized_canvas.gif and histo_maximized_canvas.pdf). In any cases, all the pdf files are equivalent, not the gif/png ones.

TH1D * histo1 = new TH1D (“histo1”,"",20,-5.,5.) ;
histo1->FillRandom(“gaus”,1000) ;
histo1->SetLineStyle(2) ;
TH1D * histo2 = new TH1D (“histo1”,"",20,-5.,5.) ;
histo2->FillRandom(“gaus”,100) ;
histo2->SetLineStyle(3) ;

TCanvas * canvas_default = new TCanvas (“canvas_default”) ;
histo1->Draw("") ;
histo2->Draw(“same”) ;
canvas_default->SaveAs(“histo_default_canvas.gif”) ;
canvas_default->SaveAs(“histo_default_canvas.png”) ;
canvas_default->SaveAs(“histo_default_canvas.pdf”) ;

gStyle->SetCanvasDefW(1440) ;
gStyle->SetCanvasDefH(900) ;
gStyle->SetCanvasDefX(0) ;
gStyle->SetCanvasDefY(0) ;
TCanvas * canvas_maximized = new TCanvas (“canvas_maximized”) ;
histo1->Draw("") ;
histo2->Draw(“same”) ;
canvas_maximized->SaveAs(“histo_maximized_canvas.gif”) ;
canvas_maximized->SaveAs(“histo_maximized_canvas.png”) ;
canvas_maximized->SaveAs(“histo_maximized_canvas.pdf”) ;

gStyle->SetCanvasDefW(320) ;
gStyle->SetCanvasDefH(240) ;
gStyle->SetCanvasDefX(0) ;
gStyle->SetCanvasDefY(0) ;
TCanvas * canvas_minimized = new TCanvas (“canvas_minimized”) ;
histo1->Draw("") ;
histo2->Draw(“same”) ;
canvas_minimized->SaveAs(“histo_minimized_canvas.gif”) ;
canvas_minimized->SaveAs(“histo_minimized_canvas.png”) ;
canvas_minimized->SaveAs(“histo_minimized_canvas.pdf”) ;
Z (66 KB)

I do not think we can achieve a perfect match. Your fixes will improve may be in some cases but will not in some other. When you change the gStyle line string, it varies every where. If you think something is wrong it should be fixed at the low level implementation for the various drivers, not like you did it. Do not forget that the line style can be user defined, so any line style should in principal look similar for all the various outputs.
So I will not put your fixes in the trunk.

My fix only works for my own case indeed. Just forget about it.
The easiest way to cope with such discrepancies is to let the user set her/his own values (in her/his rootlogon.C).

That was the whole idea of having user definable line style. :slight_smile: