Belle II Software  release-05-01-25
tracking.validation.matplotting Namespace Reference

Classes

class  defaults
 

Functions

def get_logger ()
 
def is_plotable (tobject)
 
def plot (tobject, **kwd)
 
def use_style (plot_function)
 
def plot_th2 (th2, label=None, legend=None, style=None, **kwd)
 
def plot_thstack (thstack, label=None, legend=None, style=None, **kwd)
 
def plot_tmultigraph (tmultigraph, label=None, legend=None, style=None, **kwd)
 
def plot_th1 (th1, label=None, legend=None, style=None, **kwd)
 
def plot_tgraph (tgraph, label=None, legend=None, style=None)
 
def create_figure (title=None)
 
def create_title (tplotable)
 
def create_label (th_or_tgraph, label=None)
 
def put_legend (fig, ax, legend=None, top_handles=None, top_title=None, bottom_title=None)
 
def put_legend_outside (ax, title=None, bottom=True, select_handles=[], exclude_handles=[], force_add_legend=False)
 
def get_fit (th1_or_tgraph)
 
def get_fit_parameters (tf1)
 
def get_stats_from_tgraph (tgraph)
 
def get_stats_from_th (th)
 
def compose_stats_label (title, additional_stats={})
 
def plot_tgraph_data_into (ax, tgraph, plot_errors=None, label=None, clip_to_data=True)
 
def plot_th1_data_into (ax, th1, plot_errors=None, label=None)
 
def plot_th2_data_into (ax, th2, plot_3d=False, label=None)
 
def plot_tf1_data_into (ax, tf1, label=None)
 
def root_color_to_matplot_color (root_color_index)
 
def reformat_root_latex_to_matplotlib_latex (text)
 
def is_root_latex_directive (text_part)
 
def common_bounds (matplot_bounds, root_bounds)
 

Variables

 invalid
 ignore invalid floating-point operations
 
 flt_max = sys.float_info.max
 largest possible floating-point value
 
 flt_min = sys.float_info.min
 smallest possible floating-point value
 
tuple plotable_classes
 A list of classes that are implemented as plotable. More...
 

Detailed Description

Tools to plot ROOT object into matplotlib

Function Documentation

◆ common_bounds()

def tracking.validation.matplotting.common_bounds (   matplot_bounds,
  root_bounds 
)
Assign the common lower and upper bounds for a plot

Definition at line 929 of file matplotting.py.

929 def common_bounds(matplot_bounds, root_bounds):
930  """Assign the common lower and upper bounds for a plot"""
931  lower_bound, upper_bound = matplot_bounds
932  root_lower_bound, root_upper_bound = root_bounds
933 
934  if root_lower_bound != 0 or root_upper_bound != 0:
935  lower_bound = np.nanmin((lower_bound, root_lower_bound))
936  upper_bound = np.nanmax((upper_bound, root_upper_bound))
937 
938  return lower_bound, upper_bound

◆ compose_stats_label()

def tracking.validation.matplotting.compose_stats_label (   title,
  additional_stats = {} 
)
Render the summary statistics to a label string.

Definition at line 512 of file matplotting.py.

◆ create_figure()

def tracking.validation.matplotting.create_figure (   title = None)
Create a new figure already making space for a by side legend if requested

Returns
-------
(matplotlib.figure.Figure, matplotlib.axes.Axes)
    A prepared figure and axes into which can be plotted.

Definition at line 263 of file matplotting.py.

◆ create_label()

def tracking.validation.matplotting.create_label (   th_or_tgraph,
  label = None 
)
Create a label from the plotable object incorporating available summary statistics.

Definition at line 285 of file matplotting.py.

◆ create_title()

def tracking.validation.matplotting.create_title (   tplotable)
Extract the title from the plotable ROOT object and translate to ROOT latex

Definition at line 280 of file matplotting.py.

◆ get_fit()

def tracking.validation.matplotting.get_fit (   th1_or_tgraph)
Retrieve a potential fit function form the plotable object

Definition at line 405 of file matplotting.py.

◆ get_fit_parameters()

def tracking.validation.matplotting.get_fit_parameters (   tf1)
Retrieve the fitted parameters explicitly excluding fixed parameters.

Fixed parameters are usually additional stats entries that are already shown in the main
legend for the plot.

Definition at line 412 of file matplotting.py.

◆ get_logger()

def tracking.validation.matplotting.get_logger ( )
Getter for the logger instance of this file.

Definition at line 23 of file matplotting.py.

◆ get_stats_from_tgraph()

def tracking.validation.matplotting.get_stats_from_tgraph (   tgraph)
Get the summary statistics from the graph

Definition at line 442 of file matplotting.py.

◆ get_stats_from_th()

def tracking.validation.matplotting.get_stats_from_th (   th)
Get the summary statistics from the histogram

Definition at line 454 of file matplotting.py.

◆ is_plotable()

def tracking.validation.matplotting.is_plotable (   tobject)
Indicates if a module can be plotted with matplotlib using this module.

Definition at line 60 of file matplotting.py.

◆ is_root_latex_directive()

def tracking.validation.matplotting.is_root_latex_directive (   text_part)
Test if a text part looks like a ROOT latex directive

Definition at line 924 of file matplotting.py.

◆ plot()

def tracking.validation.matplotting.plot (   tobject,
**  kwd 
)
Plot the given plotable TObject.

Parameters
----------
tobject : ROOT.TObject
    Plotable TObject.
legend : bool, optional
    Create a by-side legend containing statistical information.
style : list(str), optional
    List of matplotlib styles to be used for the plotting.

Returns
-------
matplotlib.figure.Figure
    The figure containing the plot

Definition at line 65 of file matplotting.py.

◆ plot_tf1_data_into()

def tracking.validation.matplotting.plot_tf1_data_into (   ax,
  tf1,
  label = None 
)
Plots the data of the tf1 into a matplotlib axes

Parameters
----------
ax : matplotlib.axes.Axes
    An axes space in which to plot
tf1 : ROOT.TF1
    Function to be ploted.
label : str, optional
    Label for the legend entry.

Definition at line 844 of file matplotting.py.

◆ plot_tgraph()

def tracking.validation.matplotting.plot_tgraph (   tgraph,
  label = None,
  legend = None,
  style = None 
)
Plots graph including the fit function if present

Definition at line 241 of file matplotting.py.

◆ plot_tgraph_data_into()

def tracking.validation.matplotting.plot_tgraph_data_into (   ax,
  tgraph,
  plot_errors = None,
  label = None,
  clip_to_data = True 
)
Plot a ROOT TGraph into a matplotlib axes

Parameters
----------
ax : matplotlib.axes.Axes
    An axes space in which to plot
tgraph : ROOT.TGraph
   A plotable one dimensional ROOT histogram
plot_errors : bool, optional
  Plot graph as errorbar plot. Default None means True for TGraphErrors and False else.
label : str
  label to be given to the plot

Definition at line 531 of file matplotting.py.

◆ plot_th1()

def tracking.validation.matplotting.plot_th1 (   th1,
  label = None,
  legend = None,
  style = None,
**  kwd 
)
Plots a one dimensional histogram including the fit function if present

Definition at line 211 of file matplotting.py.

◆ plot_th1_data_into()

def tracking.validation.matplotting.plot_th1_data_into (   ax,
  th1,
  plot_errors = None,
  label = None 
)
Plot a ROOT histogram into a matplotlib axes

Parameters
----------
ax : matplotlib.axes.Axes
    An axes space in which to plot
th1 : ROOT.TH1
   A plotable one dimensional ROOT histogram
plot_errors : bool, optional
  Plot histogram as errorbar plot. Default None means True for TProfile and False else.
label : str, optional
  label to be given to the histogram

Definition at line 620 of file matplotting.py.

◆ plot_th2()

def tracking.validation.matplotting.plot_th2 (   th2,
  label = None,
  legend = None,
  style = None,
**  kwd 
)
Plots a two dimensional histogram

Definition at line 129 of file matplotting.py.

◆ plot_th2_data_into()

def tracking.validation.matplotting.plot_th2_data_into (   ax,
  th2,
  plot_3d = False,
  label = None 
)
Plot a ROOT histogram into a matplotlib axes

Parameters
----------
ax : matplotlib.axes.Axes
    An axes space in which to plot
th2 : ROOT.TH2
   A plotable two dimensional ROOT histogram
plot_3d : bool, optional
  Plot as a three dimensional plot
label : str, optional
  label to be given to the histogram

Definition at line 733 of file matplotting.py.

◆ plot_thstack()

def tracking.validation.matplotting.plot_thstack (   thstack,
  label = None,
  legend = None,
  style = None,
**  kwd 
)
Plots a stack of histograms

Definition at line 147 of file matplotting.py.

◆ plot_tmultigraph()

def tracking.validation.matplotting.plot_tmultigraph (   tmultigraph,
  label = None,
  legend = None,
  style = None,
**  kwd 
)
Plots multiple overlayed graphs

Definition at line 185 of file matplotting.py.

◆ put_legend()

def tracking.validation.matplotting.put_legend (   fig,
  ax,
  legend = None,
  top_handles = None,
  top_title = None,
  bottom_title = None 
)
Put the legend of the plot

Put one legend to right beside the axes space for some plot handles if desired.
Put one legend at the bottom for the remaining plot handles.

Definition at line 313 of file matplotting.py.

◆ put_legend_outside()

def tracking.validation.matplotting.put_legend_outside (   ax,
  title = None,
  bottom = True,
  select_handles = [],
  exclude_handles = [],
  force_add_legend = False 
)
Put a legned right beside the axes space

Definition at line 352 of file matplotting.py.

◆ reformat_root_latex_to_matplotlib_latex()

def tracking.validation.matplotting.reformat_root_latex_to_matplotlib_latex (   text)
Takes text that may contain ROOT pseudo latex directives and
translate it in to proper latex that can be understood by matplotlib

Definition at line 894 of file matplotting.py.

◆ root_color_to_matplot_color()

def tracking.validation.matplotting.root_color_to_matplot_color (   root_color_index)
Translates ROOT color into an RGB tuple.

Parameters
----------
root_color_index : int
    Index  of a color as defined in ROOT

Returns
-------
(float, float, float)
    tuple of floats that represent to RGB color fractions.

Definition at line 877 of file matplotting.py.

◆ use_style()

def tracking.validation.matplotting.use_style (   plot_function)
Decorator to adjust the matplotlib style before plotting

Definition at line 103 of file matplotting.py.

Variable Documentation

◆ plotable_classes

tuple plotable_classes
Initial value:
1 = (
2  ROOT.TH1,
3  ROOT.TH2,
4  ROOT.THStack,
5  ROOT.TGraph,
6  ROOT.TGraphErrors,
7  ROOT.TMultiGraph
8 )

A list of classes that are implemented as plotable.

Definition at line 50 of file matplotting.py.