I have a TGraph with a large number of points (~1.5 Million) which I draw to a multi-pad canvas. I then save this canvas as a pdf with TCanvas::Print().
The problem is that this one plot, presumably because of its large number of points, makes the pdf document file size extremely large. This in turn causes slow render times in a pdf viewer and crashes my browser.
So the question is: Is there a way to reduce the drawing resolution of a single TObject (in this case the TGraph) on a canvas?
FYI: I’ve already tried setting the marker style to kDot, but this didn’t help enough to solve the above problems.
The attached macro generates a TGraph with 2M points and saves it as a pdf file. The file is 23MB and takes almost 30 seconds to render fully on my laptop (corei7, 16GB ram). It also crashes my browser. bigTGraph.C (307 Bytes)
$ root
----------------------------------------------------------------
| Welcome to ROOT 6.05/01 http://root.cern.ch |
| (c) 1995-2014, The ROOT Team |
| Built for macosx64 |
| From heads/master@v6-05-01-467-g66d0bad, Aug 13 2015, 14:32:14 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
----------------------------------------------------------------
root [0] .x bigTGraph.C
Info in <TCanvas::Print>: pdf file bigTGraph.pdf has been created
root [1] .q
$ ls -l bigTGraph.pdf
-rw-r--r-- 1 couet staff 23726166 Aug 14 09:29 bigTGraph.pdf
$ open bigTGraph.pdf
So the size is similar as the one you get… for me the file open in 5 seconds with “Preview” (mac viewer) and it does not crash.
Indeed, I realize for a single plot like this saving it as a raster file makes more sense. But my actual use case is to draw a plot with a similar number of points to a multi-pad TCanvas. That TCanvas is, itself, part of a larger pdf document that I’m assembling as documentation for my analysis.
So I don’t really have a choice…the canvas on which this TGraph is going to be drawn will be saved as a pdf.
in that case you may end up with that big file… Pdf is vector…
An other way you can try if to generate the png and then convert it to pdf with some external tool:
root [0] .x bigTGraph.C
Processing bigTGraph.C...
Info in <TCanvas::Print>: pdf file bigTGraph.pdf has been created
root [1] c1->Print("bigTGraph.png");
Info in <TCanvas::Print>: file bigTGraph.png has been created
root [2] .q
$ ls -l bigTGraph.png
-rw-r--r-- 1 couet staff 6281 Aug 17 09:20 bigTGraph.png
$ ls -l bigTGraph.pdf
-rw-r--r--@ 1 couet staff 23727216 Aug 17 09:19 bigTGraph.pdf
$ convert bigTGraph.png bigTGraph2.pdf
$ ls -l bigTGraph2.pdf
-rw-r--r-- 1 couet staff 4826 Aug 17 09:20 bigTGraph2.pdf
Is it possible to save such files partially as png? This is possible in matplotlib in Python for example. You can save the scatter data with millions of points as rasterized data, but other parts of the plot, e.g. axes and labels etc, as vector data, so that the final pdf is a reasonable size but also has good vector properties for rendering in documents. See for example http://www.astrobetter.com/blog/2014/01/17/slim-down-your-bloated-graphics/.
No, ROOT does not offer the possibility to save one part of the plot in png and the other one in pdf. If you have some hints on the way to do it that will be welcome. I think I depends also on the way you will include your image in te final document. Let’s take the web example. How will you include a such picture made of two files in a web page ?