Skip to content

Instantly share code, notes, and snippets.

@jepio
Last active August 29, 2015 14:02
Show Gist options
  • Save jepio/bb1dccd969fcaf493bcc to your computer and use it in GitHub Desktop.
Save jepio/bb1dccd969fcaf493bcc to your computer and use it in GitHub Desktop.
A brief instruction on how to generate tex plots and include them in tex documents.

TeX Plots

Generating using ROOT

To generate a plot start by setting the paper size. I have found that sometimes the default canvas size (in pixels) will show, so consider also creating a canvas with a specified size (aspect ratio) beforehand. Next, draw the plot and save it with a .tex extension.

gStyle->SetPaperSize(7.,4.);
plot->Draw();
gPad->Print("plot.tex");

The source file of the plot can be editted after it has been saved - you can change the axis labels, add unicode or latex characters and even change colors/sizes of every element if you're proficient in tikz.

Including in LaTeX.

To include plots, put the following in the preamble of the document:

\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{plotmarks}
\usetikzlibrary{external}
\tikzexternalize
%% or
\tikzset{external/mode=graphics if exists}

The first 3 lines include the package and the libraries used by ROOT to generate plots. The 4th line loads the library for including external graphics, in this case PDF plots. The command \tikzexternalize will generate PDF plots for every included tex plot and \tikzset{external/mode=graphics if exists} will use a PDF instead of a tex if one is present. These two commands do not work together well, so when you want to generate PDF plots leave only the first command and when you want to use them leave both. This will cause present PDF plots to be used and the rest to be compiled.

Finally, to include a plot simply use the command:

\scalebox{1}{\input{plot.tex}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment