nanslice.colorbar module

colorbar.py

Functions to create a colorbar and a dual-axis color/alphabar.

Matplotlib has no concept of an “alphabar”. In addition, because the standard matplotlib colormaps and colorbars only work on scalar (single-channel) input images, and matplotlib does not deal with alpha/transparency correctly, nanslice images are true-color RGB arrays. Hence we need to roll our own colorbar as well

nanslice.colorbar.alphabar(axes, cm_name, clims, clabel, alims, alabel, alines=None, alines_colors=('k', ), alines_styles=('solid', ), cfmt='{:.3g}', afmt='{:.2g}', black_backg=True, orient='h')[source]

Plots a 2D ‘alphabar’ with color and transparency axes in the specified matplotlib axes object

Parameters:

  • axes – matplotlib axes instance to use for plotting
  • cm_name – Colormap name
  • clims – The limits for the colormap & bar
  • clabel – Label to place on the color axis
  • alims – The limits for the transparency axis
  • alabel – Label to place on the transparency axis
  • alines – Add lines to indicate transparency values (e.g. p < 0.05). Can be a single number or an iterable
  • alines_colors – Colors to use for each alpha line. Length must match alines parameter
  • alines_styles – Line styles to use for each alpha line. Length must match alines parameter
  • cprecision – Precision of color axis ticks
  • aprecision – Precision of alpha axis ticks
  • black_bg – Boolean indicating if the background to this plot is black, and hence white text/borders should be used
  • orient – ‘v’ or ‘h’ for whether you want a vertical or horizontal colorbar
nanslice.colorbar.colorbar(axes, cm_name, clims, clabel, black_backg=True, show_ticks=True, tick_fmt='{:.2g}', orient='h')[source]

Plots a colorbar in the specified axes

Parameters:

  • axes – matplotlib axes instance to use for plotting
  • cm_name – Colormap name
  • clims – The limits for the colormap & bar
  • clabel – Label to place on the color axis
  • black_bg – Boolean indicating if the background to this plot is black, and hence white text/borders should be used
  • show_ticks – Set to false if you don’t want ticks on the color axis
  • tick_fmt – Valid format string for the tick labels
  • orient – ‘v’ or ‘h’ for whether you want a vertical or horizontal colorbar