HErmes.plotting package

Submodules

HErmes.plotting.canvases module

Provides canvases for multi axes plots

HErmes.plotting.canvases.Image(x)[source]
class HErmes.plotting.canvases.YStackedCanvas(subplot_yheights=(0.2, 0.2, 0.5), padding=(0.15, 0.05, 0.0, 0.1), space_between_plots=0, figsize='auto', figure_factory=None)[source]

Bases: object

A canvas for plotting multiple axes

eliminate_lower_yticks()[source]

Eliminate the lowest y tick on each axes. The bottom axes keeps its lowest y-tick.

global_legend(*args, **kwargs)[source]

A combined legend for all axes

Parameters:args will be passed to pylab.legend (all) –
Keyword Arguments:
 kwargs will be passed to pylab.legend (all) –
limit_xrange(xmin=None, xmax=None)[source]

Walk through all axes and set xlims

Keyword Arguments:
 
  • xmin (float) – left x edge of axes
  • xmax (float) – right x edge of axes
Returns:

None

limit_yrange(ymin=None, ymax=None)[source]

Walk through all axes and adjust ymin and ymax

Keyword Arguments:
 ymin (float) – min ymin value
save(path, name, formats=('pdf', 'png'), **kwargs)[source]

Calls pylab.savefig for all endings

Parameters:
  • path (str) – path to savefile
  • name (str) – filename to save
  • formats (tuple) – for each name in endings, a file is save
Keyword Arguments:
 

keyword args will be passed to pylab.savefig (all) –

Returns:

The full path to the the saved file

Return type:

str

select_axes(axes)[source]

Set the scope on a certain axes

Parameters:axes (int) – 0 lowest, -1 highest, increasing y-order
Returns:The axes instance
Return type:matplotlib.axes.axes
show()[source]

Use the IPython.core.Image to show the plot

Returns:the plot
Return type:IPython.core.Image

HErmes.plotting.colors module

Color management - provide a nice color scheme even if seaborn is not available

class HErmes.plotting.colors.ColorDict[source]

Bases: dict

Use to transparently map any non defined colors through, like string like ‘k’ for matplotlib

HErmes.plotting.colors.get_color_palette(name='dark')[source]

Load a color pallete, use seaborn if available.

Keyword Arguments:
 name (str) – A string which is passed though seaborn.color_palette
Returns:HErmes.plotting.plot_colors.ColorDict

HErmes.plotting.layout module

A set of figure sizes for publication-ready figures on A4 paper based on the golden ratio. For the use with pylabe figure, e.g. fig =pylab.figure(figsize=FIGSIZE_A4)

Available layouts:

  • FIGSIZE_A4: Figure on full A4 width, portrait mode, golden ratio
  • FIGSIZE_A4_LANDSCAPE: Figure on full A4 width, landscape mode, golden ratio
  • FIGSIZE_A4_LANDSCAPE_HALF_HEIGHT: Figure on full A4 width, landscape mode, height half of golden ratio
  • FIGSIZE_A4_SQUARE: Figure on full A4 width, square

HErmes.plotting.plotting module

Define some

class HErmes.plotting.plotting.VariableDistributionPlot(cuts=None, color_palette='dark', bins=None, xlabel=None)[source]

Bases: object

A plot which shows the distribution of a certain variable. Cuts can be indicated with lines and arrows. This class defines (and somehow enforces) a certain style.

add_cumul(name)[source]

Add a cumulative distribution to the plto

Parameters:name (str) – the name of the category
add_cuts(cut)[source]

Add a cut to the the plot which can be indicated by an arrow

Parameters:cuts (HErmes.selection.cuts.Cut) –
Returns:None
add_data(variable_data, name, bins=None, weights=None, label='')[source]

Histogram the added data and store internally

Parameters:
  • name (string) – the name of a category
  • variable_data (array) – the actual data
Keyword Arguments:
 
  • bins (array) – histogram binning
  • weights (array) – weights for the histogram
  • label (str) – A label for the data when plotted
add_legend(**kwargs)[source]

Add a legend to the plot. If no kwargs are passed, use some reasonable default.

Keyword Arguments:
 be passed to pylab.legend (will) –
add_ratio(nominator, denominator, total_ratio=None, total_ratio_errors=None, log=False, label='data/$\\Sigma$ bg')[source]

Add a ratio plot to the canvas

Parameters:
  • nominator (list or str) – name(s) of the categorie(s) which will be the nominator in the ratio
  • denominator (list or str) – name(s) of the categorie(s) which will be the nominator in the ratio
Keyword Arguments:
 
  • total_ratio (bool) – Indicate the total ratio with a line in the plot
  • total_ratio_errors (bool) – Draw error region around total ratio
  • log (bool) – draw ratio plot in log-scale
  • label (str) – y-label for the ratio plot
add_variable(category, variable_name, external_weights=None, transform=None)[source]

Convenience interface if data is sorted in categories already

Parameters:
  • category (HErmese.variables.category.Category) – Get variable from this category
  • variable_name (string) – The name of the variable
Keyword Arguments:
 
  • external_weights (np.ndarray) – Supply an array for weighting. This will OVERIDE ANY INTERNAL WEIGHTING MECHANISM and use the supplied weights.
  • transform (callable) – Apply transformation todata
indicate_cut(ax, arrow=True)[source]

If cuts are given, indicate them by lines

Parameters:ax (pylab.axes) – axes to draw on
static optimal_plotrange_histo(histograms)[source]

Get most suitable x and y limits for a bunc of histograms

Parameters:histograms (list(d.factory.hist1d)) – The histograms in question
Returns:xmin, xmax, ymin, ymax
Return type:tuple (float, float, float, float)
plot(axes_locator=((0, 'c', 0.2), (1, 'r', 0.2), (2, 'h', 0.5)), combined_distro=True, combined_ratio=True, combined_cumul=True, normalized=True, log=True, legendwidth=1.5, ylabel='rate/bin [1/s]', figure_factory=None)[source]

Create the plot

Keyword Arguments:
 
  • heights
  • axes_locator
  • combined_distro
  • combined_ratio
  • combined_cumul
  • log
  • normalized (bool) –

Returns:

HErmes.plotting.plotting.adjust_minor_ticks(axis, which='x')[source]

Decorate the x-axis with a reasonable set of minor x-ticks

Parameters:axis (matplotlib.axis) – The axis to decorate
Keyword Arguments:
 which (str) – either “x”, “y” or “both”
Returns:matplotlib.axis
HErmes.plotting.plotting.create_arrow(ax, x_0, y_0, dx, dy, length, width=0.1, shape='right', fc='k', ec='k', alpha=1.0, log=False)[source]

Create an arrow object for plots. This is typically a large arrow, which can used to indicate a region in the plot which is excluded by a cut.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The axes where the arrow will be attached to
  • x_0 (float) – x-origin of the arrow
  • y_0 (float) – y-origin of the arrow
  • dx (float) – x length of the arrow
  • dy (float) – y length of the arrow
  • length (float) – additional scaling parameter to scale the length of the arrow
Keyword Arguments:
 
  • width (float) – thickness of arrow
  • shape (str) – either “full”, “left” or “right”
  • fc (str) – facecolor
  • ec (str) – edgecolor
  • alpha (float) – 0 -1 alpha value of the arrow
  • log (bool) – I for logscale, the proportions of the arrow will be adjusted accorginly.
Returns:

matplotlib.axes._subplots.AxesSubplot

HErmes.plotting.plotting.line_plot(quantities, bins=None, xlabel='', add_ratio=None, ratiolabel='', colors=None, figure_factory=None)[source]
Parameters:

quantities

Keyword Arguments:
 
  • bins
  • xlabel
  • add_ratio (tuple) – ([“data1”],[“data2”])
  • ratiolabel (str) –
  • colors
  • figure_factory (callable) – Factory function returning matpltolib.Figure

Returns:

HErmes.plotting.plotting.meshgrid(xs, ys)[source]

Create x and y data for matplotlib pcolormesh and similar plotting functions.

Parameters:
  • xs (np.ndarray) – 1d x bins
  • ys (np.ndarray) – 2d y bins
Returns:

2d X and 2d Y matrices as well as a placeholder for the Z array

Return type:

tuple (np.ndarray, np.ndarray, np.ndarray)

Module contents

A set of

HErmes.plotting.add_styles()[source]