fsleyes_widgets.utils.colourbarbitmap
This module provides a single function, colourBarBitmap()
, which uses
matplotlib
to plot a colour bar. The colour bar is rendered off-screen
and returned as an RGBA bitmap.
- fsleyes_widgets.utils.colourbarbitmap.colourBarBitmap(cmap, width, height, cmapResolution=256, negCmap=None, invert=False, gamma=1, ticks=None, ticklabels=None, tickalign=None, label=None, orientation='vertical', labelside='top', alpha=1.0, fontsize=10, bgColour=None, textColour='#ffffff', scale=1.0, interp=False, logScaleRange=None, modAlpha=False, invModAlpha=False, displayRange=None, modRange=None)[source]
Plots a colour bar using
matplotlib
.The rendered colour bar is returned as a RGBA bitmap within a
numpy.uint8
array of size \(w \times h \times 4\), with the top-left pixel located at index[0, 0, :]
.A rendered colour bar will look something like this:
- Parameters:
cmap – Name of a registered
matplotlib
colour map.width – Colour bar width in pixels.
height – Colour bar height in pixels.
cmapResolution – Colour map resolution (number of distinct colours).
negCmap – If provided, two colour maps are drawn, centered at 0.
invert – If
True
, the colour map is inverted.gamma – Gamma correction factor - exponentially weights the colour map scale towards one end.
ticks – Locations of tick labels. Ignored if
ticklabels is None
.ticklabels – Tick labels.
tickalign – Tick alignment (one for each tick, either
'left'
,'right'
, or'center'
).label – Text label to show next to the colour bar.
orientation – Either
vertical
orhorizontal
.labelside – Side of the colour bar to put the label -
top
,bottom
,left
orright
. Iforientation='vertical'
, thentop
/bottom
are interpreted asleft
/right
(and vice-versa whenorientation='horizontal'
).alpha – Colour bar transparency, in the range
[0.0 - 1.0]
.fontsize – Label font size in points.
bgColour – Background colour - can be any colour specification that is accepted by
matplotlib
.textColour – Label colour - can be any colour specification that is accepted by
matplotlib
.scale – DPI scaling factor.
interp – If true, and the colour map has fewer colours than
cmapResolution
, it is linearly interpolated to havecmapResolution
.logScaleRange – Tuple containing
(min, max)
display range to which the colour bar is mapped to. If provided, the colour bar will be scaled to the natural logarithm of the display range.modAlpha – If
True
, modulate the colour bar transparency according to the modulate and display ranges, so that colours at or below the low modulation range are fully transparent, and colours at or above the high modulation range have transparency set toalpha
.invModAlpha – If
True
, flips the direction in which the colour bar is modulated by transparency.displayRange – Low/high values corresponding to the low/high colours. Required when
modAlpha=True
.modRange – Low/high values between which transparency should be modulated. Required when
modAlpha=True
.