diff --git a/examples/basics/scene/colorbar_widget.py b/examples/basics/scene/colorbar_widget.py index 24fb166ba5..bf0a24161a 100644 --- a/examples/basics/scene/colorbar_widget.py +++ b/examples/basics/scene/colorbar_widget.py @@ -16,11 +16,11 @@ canvas.show() grid = canvas.central_widget.add_grid(margin=10) - -cbar_widget = scene.ColorBarWidget(cmap="cool", orientation="right") +cbar_widget = scene.ColorBarWidget(label="ColorBarWidget", clim=(0, 99), + cmap="cool", orientation="right", + border_width=1) grid.add_widget(cbar_widget) -cbar_widget.pos = (300, 100) cbar_widget.border_color = "#212121" grid.bgcolor = "#ffffff" diff --git a/vispy/scene/widgets/colorbar.py b/vispy/scene/widgets/colorbar.py index fba1036b7b..85cb8d42b6 100644 --- a/vispy/scene/widgets/colorbar.py +++ b/vispy/scene/widgets/colorbar.py @@ -67,13 +67,14 @@ class ColorBarWidget(Widget): minor_axis_ratio = 0.05 def __init__(self, cmap, orientation, - label="", clim=("", ""), + label="", clim=("", ""), label_color='black', border_width=0.0, border_color="black", **kwargs): dummy_size = (1, 1) self._colorbar = ColorBarVisual(size=dummy_size, cmap=cmap, orientation=orientation, - label=label, clim=clim, + label_str=label, clim=clim, + label_color=label_color, border_width=border_width, border_color=border_color, **kwargs) @@ -141,6 +142,14 @@ def label(self): def label(self, label): self._colorbar.label = label + @property + def ticks(self): + return self._colorbar.ticks + + @ticks.setter + def ticks(self, ticks): + self._colorbar.ticks = ticks + @property def clim(self): return self._colorbar.clim @@ -149,6 +158,26 @@ def clim(self): def clim(self, clim): self._colorbar.clim = clim + @property + def border_color(self): + """ The color of the border around the ColorBar in pixels + """ + return self._colorbar.border_color + + @border_color.setter + def border_color(self, border_color): + self._colorbar.border_color = border_color + + @property + def border_width(self): + """ The width of the border around the ColorBar in pixels + """ + return self._colorbar.border_width + + @border_width.setter + def border_width(self, border_width): + self._colorbar.border_width = border_width + @property def orientation(self): return self._colorbar.orientation diff --git a/vispy/visuals/colorbar.py b/vispy/visuals/colorbar.py index 70e2c60fb4..e8af595fe7 100644 --- a/vispy/visuals/colorbar.py +++ b/vispy/visuals/colorbar.py @@ -275,23 +275,25 @@ class ColorBarVisual(CompoundVisual): def __init__(self, cmap, orientation, size, pos=[0, 0], label_str="", + label_color='black', clim=(0.0, 1.0), border_width=1.0, border_color="black", **kwargs): self._label_str = label_str + self._label_color = label_color self._cmap = get_colormap(cmap) self._clim = clim self._pos = pos self._size = size self._orientation = orientation - self._label = TextVisual(text=self._label_str) + self._label = TextVisual(self._label_str, color=self._label_color) self._ticks = [] - self._ticks.append(TextVisual(str(self._clim[0]))) - self._ticks.append(TextVisual(str(self._clim[1]))) + self._ticks.append(TextVisual(str(self._clim[0]), color=self._label_color)) + self._ticks.append(TextVisual(str(self._clim[1]), color=self._label_color)) if orientation in ["top", "bottom"]: (width, height) = size @@ -323,7 +325,6 @@ def _update(self): self._colorbar.halfdim = self._halfdim self._border.halfdim = self._halfdim - self._label.text = self._label_str self._ticks[0].text = str(self._clim[0]) self._ticks[1].text = str(self._clim[1]) @@ -634,6 +635,7 @@ def border_color(self): @border_color.setter def border_color(self, border_color): self._border.border_color = border_color + self._update() @property def orientation(self):