Matplotlib

From AstroNuWiki
Jump to: navigation, search

Here I will post some tricks helping to plot ROOT objects with matplotlib Python module.

Requirements

  1. Python
  2. ROOT compiled with Python support
  3. matplotlib and scipy Python modules

Plotting

Python module r2mpl.py defines 'draw' method for TH1, TH2, TF1, TGraph, TGraphErrors, TGraphAsymmErrors for plotting with matplotlib:

  • TH1.draw draws line and bars and is used as plot. Additional options can be passed via 'baropts=dict()' to bar
  • TH1.drawLine draws lines only and is used as plot
  • TH1.drawBar draws bars and is used as bar
  • TGraph.draw is used as plot
  • TGraphErrors.draw/TGraphAsymmErrors.draw are used as errorbar
  • TH2.draw is used as pcolorfast
  • TH2.drawMesh is used as pcolormesh
  • TF1.draw(x) is used as plot. 'x' is an array of points along X axis to plot, number of points to plot (if 'x' is an integer), step of plotting (if 'x' is float)

TH2.draw and TH2.drawMesh accept additional option colz=True to plot colorbar, and mask=0.0 (or another number) to make zero bins white as in ROOT.