sciplot package

Submodules

sciplot.analysis module

Analysis tools

sciplot.analysis.data_mc_ratio(data, mc, label_data='Data', label_mc='MC', y_label=None, figsize=None, ratio_range=(0, 2), *args, **kwarg)[source]

Plot a comparison between two sets of data

Parameters:
  • data
  • mc
  • label_data
  • label_mc
  • y_label
  • figsize
  • ratio_range
  • *args
  • **kwarg

Returns:

sciplot.analysis.plot_flatness(sig, tag, bins=None, ax=None, xrange=None, percent_step=5)[source]

Plotting differences of sig distribution in percentiles of tag distribution

Parameters:
  • sig
  • tag
  • bins
  • ax
  • xrange
  • percent_step

Returns:

sciplot.analysis.profile(x, y, bins=None, range=None, fmt='.', *args, **kwargs)[source]
sciplot.analysis.ratio(y1, y2, y1_err=None, y2_err=None)[source]

calculate the ratio between two histograms y1/y2

Parameters:
  • y1 – y values of first histogram
  • y2 – y values of second histogram
  • y1_err – (optional) error of first
  • y2_err – (optional) error of second
Returns:

ratio, ratio_error

sciplot.colors module

Color definitions

Here are some predefined colors for nicer plots.

sciplot.colors.b2blues(n=5)[source]
sciplot.colors.b2greens(n=3)[source]
sciplot.colors.b2helix(n)[source]
sciplot.colors.cm(n)[source]

sciplot.decorations module

sciplot.decorations.decorate(*args, **kwargs)[source]
sciplot.decorations.draw_y_label(label='Entries', unit=None, ha='right', *args, **kwargs)[source]

Plotting scientific notation y label

Parameters:
  • label
  • unit
  • ha
  • *args
  • **kwargs

Returns:

sciplot.decorations.expand(factor=1.2)[source]
sciplot.decorations.labels(xlabel=None, ylabel=None, unit=None, root_style=False, *args, **kwargs)[source]
sciplot.decorations.set_style()[source]
sciplot.decorations.watermark(t1='Collaboration', t2='(preliminary)', px=0.5, py=0.9, fontsize=16, alpha=0.95, *args, **kwargs)[source]

sciplot.functions module

In this file all the matplolib wrappers are located.

sciplot.functions.errorbar(bin_centers, y, y_err, x_err=None, box=False, plot_zero=True, fmt='.', color=None, ax=None, label=None, *args, **kwargs)[source]
sciplot.functions.errorhist(data, bins=None, color=None, normed=False, fmt='.', range=None, scale=None, x_err=False, box=False, ax=None, weights=None, plot_zero=True, label=None, *args, **kwargs)[source]
Parameters:
  • data
  • bins
  • color
  • normed
  • fmt
  • range
  • scale
  • x_err
  • box
  • ax
  • weights
  • plot_zero
  • label
  • *args
  • **kwargs

Returns:

sciplot.functions.hist(data, bins=None, fill=False, range=None, lw=1.0, ax=None, style=None, color=None, scale=None, weights=None, label=None, edgecolor=None, *args, **kwargs)[source]
Parameters:
  • data
  • bins
  • fill
  • range
  • lw
  • ax
  • style
  • color
  • scale
  • weights
  • *args
  • **kwargs

Returns:

sciplot.functions.save(filename, bottom=0.15, left=0.13, right=0.96, top=0.95, *args, **kwargs)[source]

Save a file and do the subplot_adjust to fit the page with larger labels

Parameters:
  • filename
  • bottom
  • left
  • right
  • top
  • *args
  • **kwargs

Returns:

sciplot.functions.sig_bkg_plot(df, col, by=None, ax=None, bins=None, range=None, labels=None)[source]
sciplot.functions.stacked(df, col=None, by=None, bins=None, color=None, range=None, lw=0.5, ax=None, edgecolor='black', *args, **kwargs)[source]

Create stacked histogram

Parameters:
  • df (DataFrame or list of arrays) –
  • col
  • by
  • bins
  • color
  • lw
  • *args
  • **kwargs

Returns:

sciplot.functions.text(t, x=0.8, y=0.9, fontsize=22, *args, **kwargs)[source]
Parameters:
  • t
  • x
  • y
  • fontsize
  • *args
  • **kwargs

Returns:

sciplot.functions.to_stack(df, col, by)[source]
Parameters:
  • df
  • col
  • by

Returns:

sciplot.functions.xlim(low=None, high=None, ax=None)[source]
Parameters:
  • low
  • high
  • ax

Returns:

sciplot.helpers module

Helper function and classes are defined here.

class sciplot.helpers.Singleton(decorated)[source]

Bases: object

A non-thread-safe helper class to ease implementing singletons. This should be used as a decorator – not a metaclass – to the class that should be a singleton.

The decorated class can define one __init__ function that takes only the self argument. Other than that, there are no restrictions that apply to the decorated class.

To get the singleton instance, use the Instance method. Trying to use __call__ will result in a TypeError being raised.

Limitations: The decorated class cannot be inherited from.

Instance()[source]

Returns the singleton instance. Upon its first call, it creates a new instance of the decorated class and calls its __init__ method. On all subsequent calls, the already created instance is returned.

sciplot.helpers.figure()[source]
sciplot.helpers.get_optimal_bin_size(n)[source]

This function calculates the optimal amount of bins for the number of events n. :param n: number of Events :return: optimal bin size

sciplot.helpers.hist2root(h, name=None, title='')[source]

Convert your histograms to a root histogram.. if you really want to

Parameters:
  • h – array with the histogram h=(y_values, bin_edges, (patches=optional))
  • name – Name for the root histogram, optional
  • title – Title for the root histogram, optional
Returns:

TH1F or TH2F depending on the input array

Examples

>>> data = [1,2,3,4,5,6,7]
>>> h = b2plot.hist(data)
>>> from b2plot.helpers import hist2root
>>> root_hist = hist2root(h)
sciplot.helpers.nf()[source]
sciplot.helpers.xaxis()[source]

sciplot.skeleton module

This is a skeleton file that can serve as a starting point for a Python console script. To run this script uncomment the following lines in the [options.entry_points] section in setup.cfg:

console_scripts =
fibonacci = sciplot.skeleton:run

Then run python setup.py install which will install the command fibonacci inside your current environment. Besides console scripts, the header (i.e. until _logger…) of this file can also be used as template for Python modules.

Note: This skeleton file can be safely removed if not needed!

sciplot.skeleton.fib(n)[source]

Fibonacci example function

Parameters:n (int) – integer
Returns:n-th Fibonacci number
Return type:int
sciplot.skeleton.main(args)[source]

Main entry point allowing external calls

Parameters:args ([str]) – command line parameter list
sciplot.skeleton.parse_args(args)[source]

Parse command line parameters

Parameters:args ([str]) – command line parameters as list of strings
Returns:command line parameters namespace
Return type:argparse.Namespace
sciplot.skeleton.run()[source]

Entry point for console_scripts

sciplot.skeleton.setup_logging(loglevel)[source]

Setup basic logging

Parameters:loglevel (int) – minimum loglevel for emitting messages

Module contents