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

Merge branch 'bf/colourbarbitmap_xlim' into 'master'

Bf/colourbarbitmap xlim

See merge request fsl/fsleyes/widgets!22
parents 8c4f81e7 cc3c4be8
......@@ -12,11 +12,14 @@ fi;
source /test.venv/bin/activate
pip install -r requirements-dev.txt
pip install -r requirements.txt
PIPARGS="--retries 10 --timeout 30"
pip install $PIPARGS -r requirements-dev.txt
pip install $PIPARGS -r requirements.txt
# style stage
if [ "$TEST_STYLE"x != "x" ]; then pip install pylint flake8; fi;
if [ "$TEST_STYLE"x != "x" ]; then pip install $PIPARGS pylint flake8; fi;
if [ "$TEST_STYLE"x != "x" ]; then flake8 fsleyes_widgets || true; fi;
if [ "$TEST_STYLE"x != "x" ]; then pylint --output-format=colorized fsleyes_widgets || true; fi;
if [ "$TEST_STYLE"x != "x" ]; then exit 0; fi
......
......@@ -44,48 +44,50 @@ def colourBarBitmap(cmap,
:align: center
:arg cmap: Name of a registered :mod:`matplotlib` colour map.
:arg cmap: Name of a registered :mod:`matplotlib` colour map.
:arg width: Colour bar width in pixels.
:arg width: Colour bar width in pixels.
:arg height: Colour bar height in pixels.
:arg height: Colour bar height in pixels.
:arg negCmap: If provided, two colour maps are drawn, centered at 0.
:arg cmapResolution: Colour map resolution (number of distinct colours).
:arg invert: If ``True``, the colour map is inverted.
:arg negCmap: If provided, two colour maps are drawn, centered at 0.
:arg gamma: Gamma correction factor - exponentially weights the
colour map scale towards one end.
:arg invert: If ``True``, the colour map is inverted.
:arg ticks: Locations of tick labels. Ignored if
``ticklabels is None``.
:arg gamma: Gamma correction factor - exponentially weights the
colour map scale towards one end.
:arg ticklabels: Tick labels.
:arg ticks: Locations of tick labels. Ignored if
``ticklabels is None``.
:arg tickalign: Tick alignment (one for each tick, either ``'left'``,
``'right'``, or ``'center'``).
:arg ticklabels: Tick labels.
:arg label: Text label to show next to the colour bar.
:arg tickalign: Tick alignment (one for each tick, either ``'left'``,
``'right'``, or ``'center'``).
:arg orientation: Either ``vertical`` or ``horizontal``.
:arg label: Text label to show next to the colour bar.
:arg labelside: Side of the colour bar to put the label - ``top``,
``bottom``, ``left`` or ``right``. If
``orientation='vertical'``, then ``top``/``bottom``
are interpreted as ``left``/``right`` (and vice-versa
when ``orientation='horizontal'``).
:arg orientation: Either ``vertical`` or ``horizontal``.
:arg alpha: Colour bar transparency, in the range ``[0.0 - 1.0]``.
:arg labelside: Side of the colour bar to put the label - ``top``,
``bottom``, ``left`` or ``right``. If
``orientation='vertical'``, then ``top``/``bottom``
are interpreted as ``left``/``right`` (and vice-versa
when ``orientation='horizontal'``).
:arg fontsize: Label font size in points.
:arg alpha: Colour bar transparency, in the range ``[0.0 - 1.0]``.
:arg bgColour: Background colour - can be any colour specification
that is accepted by :mod:`matplotlib`.
:arg fontsize: Label font size in points.
:arg textColour: Label colour - can be any colour specification that
is accepted by :mod:`matplotlib`.
:arg bgColour: Background colour - can be any colour specification
that is accepted by :mod:`matplotlib`.
:arg scale: DPI scaling factor.
: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
......@@ -116,6 +118,12 @@ def colourBarBitmap(cmap,
if labelside == 'left': labelside = 'top'
else: labelside = 'bottom'
# force tick positions to
# the left edge of the
# corresponding colour
if ticks is not None:
ticks = [t - 0.5 / cmapResolution for t in ticks]
# Default is 96 dpi to an inch
winches = width / 96.0
hinches = height / 96.0
......@@ -143,8 +151,6 @@ def colourBarBitmap(cmap,
origin='lower',
interpolation='nearest')
ax.set_xlim((0, ncols - 1))
ax.set_yticks([])
ax.tick_params(colors=textColour, labelsize=fontsize, length=0)
......@@ -212,6 +218,8 @@ def colourBarBitmap(cmap,
for l, a in zip(ticklabels, tickalign):
l.set_horizontalalignment(a)
ax.set_xlim((-0.5, ncols - 0.5))
canvas.draw()
buf = canvas.tostring_argb()
......
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