Commit d3852354 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'enh/colourbar_scale' into 'master'

Scale parameter for colourbarbitmap

See merge request fsl/fsleyes/widgets!18
parents 96ad0266 6c1e772f
......@@ -27,7 +27,8 @@ def colourBarBitmap(cmap,
alpha=1.0,
fontsize=10,
bgColour=None,
textColour='#ffffff'):
textColour='#ffffff',
scale=1.0):
"""Plots a colour bar using :mod:`matplotlib`.
......@@ -83,6 +84,8 @@ def colourBarBitmap(cmap,
:arg textColour: Label colour - can be any colour specification that
is accepted by :mod:`matplotlib`.
:arg scale: DPI scaling factor.
"""
# These imports are expensive, so we're
......@@ -113,18 +116,21 @@ def colourBarBitmap(cmap,
if labelside == 'left': labelside = 'top'
else: labelside = 'bottom'
dpi = 96.0
ncols = cmapResolution
data = genColours(cmap, ncols, invert, alpha, gamma)
# Default is 96 dpi to an inch
winches = width / 96.0
hinches = height / 96.0
dpi = scale * 96.0
ncols = cmapResolution
data = genColours(cmap, ncols, invert, alpha, gamma)
if negCmap is not None:
ndata = genColours(negCmap, ncols, not invert, alpha, gamma)
data = np.concatenate((ndata, data), axis=1)
ncols *= 2
fig = mplfig.Figure(figsize=(width / dpi, height / dpi), dpi=dpi)
canvas = mplagg.FigureCanvasAgg(fig)
ax = fig.add_subplot(111)
fig = mplfig.Figure(figsize=(winches, hinches), dpi=dpi)
canvas = mplagg.FigureCanvasAgg(fig)
ax = fig.add_subplot(111)
if bgColour is not None:
fig.patch.set_facecolor(bgColour)
......
......@@ -283,6 +283,40 @@ def test_label_and_ticks():
assert _compare(bmp, fname)
def test_scale():
scales = [0.5, 1.0, 2.0, 3.0]
orientations = ['horizontal', 'vertical']
labelsides = ['top', 'bottom']
testcases = it.product(scales,
orientations,
labelsides)
ticks = [0.1, 0.9]
ticklabels = [str(t) for t in ticks]
label = 'Label'
for scale, orient, side in testcases:
if orient[0] == 'v': width, height = 100, 300
else: width, height = 300, 100
bmp = cbarbmp.colourBarBitmap('Reds',
width,
height,
ticks=ticks,
ticklabels=ticklabels,
label=label,
orientation=orient,
labelside=side,
scale=scale,
textColour=(0, 0, 0.2, 1))
fname = '_'.join([str(scale), orient, side])
fname = 'scale_{}.png'.format(fname)
assert _compare(bmp, fname)
def test_badargs():
testcases = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment