Tutorial V: Plotting with ROOT and MPL - KIT-CMS/Artus GitHub Wiki

This tutorial is based on the ROOT files generated in the first step.

There are three important plotting modules in HarryPlotter: PlotRoot, PlotMpl and ExportRoot. The first two generate plots using either ROOT or matplotlib functionallity. The corresponding options and settings are compared in this tutorial side-by-side. The latter module is used to write ROOT objects, that have been generated during a HarryPlotter run into ROOT files.

Drawing options for different ROOT objects

Histograms

  • Filled 1D histogram

     harry.py --plot-modules PlotRoot -m HIST -i gaussians3.root -f gaussians1 -x var0
     harry.py --plot-modules PlotMpl -m bar -i gaussians3.root -f gaussians1 -x var0

    plots/histogram_1d_filled_root.png plots/histogram_1d_filled_mpl.png

  • 1D histogram as line

     harry.py --plot-modules PlotRoot -m LINE -i gaussians3.root -f gaussians1 -x var0
     # harry.py --plot-modules PlotMpl <options> -i gaussians3.root -f gaussians1 -x var0

    plots/histogram_1d_line_root.png plots/histogram_1d_line_mpl.png

  • 1D histogram with points and error bars

     harry.py --plot-modules PlotRoot -m E -i gaussians3.root -f gaussians1 -x var0
     harry.py --plot-modules PlotMpl -m o -i gaussians3.root -f gaussians1 -x var0

    plots/histogram_1d_errorbar_root.png plots/histogram_1d_errorbar_mpl.png

  • Stacking of 1D histograms

    Stacking of histograms is controlled via the option --stacks, which is a plotting and not an input option. For each object to be plotted it takes an arbitrary string naming the stack(s). Objects with the same stack name are stacked. This option is independent of the actual plotting backend, namely PlotRoot and PlotMpl.

     harry.py --stacks stack1 stack1 stack1 stack2 stack3 -i gaussians3.root -f gaussians1 -x var0 --scale-factors 0.5 0.3 0.2 1.0 0.4 --plot-modules PlotRoot -m HIST HIST HIST E LINE --labels "Scale 0.5" "Scale 0.3" "Scale 0.2" "Scale 1.0" "Scale 0.4" --legend-markers F F F ELP L --legend 0.2 0.6 0.5 0.9
     harry.py --stacks stack1 stack1 stack1 stack2 stack3 -i gaussians3.root -f gaussians1 -x var0 --scale-factors 0.5 0.3 0.2 1.0 0.4 --plot-modules PlotMpl -m bar bar bar o o --labels "Scale 0.5" "Scale 0.3" "Scale 0.2" "Scale 1.0" "Scale 0.4" --legend best

    plots/histograms_1d_stack_root.png plots/histograms_1d_stack_mpl.png

  • 2D histograms

     harry.py --plot-modules PlotRoot -m COLZ -i gaussians3.root -f gaussians1 -x var0 -y var1
     harry.py --plot-modules PlotMpl --colormap -i gaussians3.root -f gaussians1 -x var0 -y var1

    plots/histogram_2d_colormap_root.png plots/histogram_2d_colormap_mpl.png

Drawing Graphs

  • 1D Graphs as points with error bars

     harry.py --plot-modules PlotRoot -m P -i gaussians3.root -f gaussians1 -x Entry$:0.3 -y "var0:sqrt(abs(var0))" --tree-draw-options TGraphErrors -w "Entry$ < 20"
     harry.py --plot-modules PlotMpl -m o -i gaussians3.root -f gaussians1 -x Entry$:0.3 -y "var0:sqrt(abs(var0))" --tree-draw-options TGraphErrors -w "Entry$ < 20"

    plots/graph_1d_errobar_root.png plots/graph_1d_errobar_mpl.png

  • 1D Graphs as lines

     harry.py --plot-modules PlotRoot -m L -i gaussians3.root -f gaussians1 -x Entry$ -y var0 --tree-draw-options TGraph -w "Entry$ < 20"
     harry.py --plot-modules PlotMpl --line-styles - -i gaussians3.root -f gaussians1 -x Entry$ -y var0 --tree-draw-options TGraph -w "Entry$ < 20"

    plots/graph_1d_line_root.png plots/graph_1d_line_mpl.png

Drawing Functions

  • 1D functions as lines

     harry.py --plot-modules PlotRoot -m L --input-modules InputInteractive -x "x^2" --x-bins 100,-10,10
     # harry.py --plot-modules PlotMpl <options> --input-modules InputInteractive -x "x^2" --x-bins 100,-10,10

    plots/function_1d_line_root.png plots/function_1d_line_mpl.png

  • 2D functions

     harry.py --plot-modules PlotRoot -m COLZ --input-modules InputInteractive -x "x*y" --x-bins 100,-10,10 --y-bins 100,-10,10
     # harry.py --plot-modules PlotMpl <options> --input-modules InputInteractive -x "x*y" --x-bins 100,-10,10 --y-bins 100,-10,10

    plots/function_2d_colormap_root.png plots/function_2d_colormap_mpl.png

⚠️ **GitHub.com Fallback** ⚠️