# "Color Scalar Bar" reworked and upgraded, now it’s called "Color Legend"

**URL:** <https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567>\
**Category:** Support\
**Tags:** feature\
**Created:** [January 22, 2022, 7:56am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567 "2022-01-22T07:56:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 22, 2022, 7:56am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/1 "2022-01-22T07:56:40Z")

</div>

Starting from version [30530 build 2022-01-15](https://github.com/Slicer/Slicer/pull/5828/commits/170a0e0edd448fd2c5d8e47ac6de591293fc8354) “Color Scalar Bar” section from “Colors” module was replaced with “Color Legend” section.

The “Color Legend” section has been also added to the “Volume”, “Model” and “Markups” modules to control visibility and behavior of color legend.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/7/6755ea30878f4e57abb5e25ea985518b838bea3e.jpeg)

New major features:

1. More unified API. Each Volume, Model, Markups or any other displayable node now can have an individual color legend by means of [vtkMRMLColorLegendDisplayNode](https://apidocs.slicer.org/master/classvtkMRMLColorLegendDisplayNode.html).

2. Displayed LUT is in sync with range of displayed values of primary display node;

3. Resizable title of color legend;

4. Control of visibility of color legend on each slice or 3D view.

5. Color legend can by added to any displayable node (if the node has a primary display node) by means of [Color module logic](http://apidocs.slicer.org/master/classvtkSlicerColorLogic.html#ab3c6cd1c528e5c826dba15826043a4ea) and AddDefaultColorLegendDisplayNode method.

6. The access to a low level [vtkScalarBarActor](https://vtk.org/doc/nightly/html/classvtkScalarBarActor.html) for developers and experienced users is described [here](https://slicer.readthedocs.io/en/latest/developer_guide/modules/colors.html#access-scalar-bar-actor).

There are still some features that must be added. [Issue](https://github.com/Slicer/Slicer/issues/6111) to check the progress is here.

Any other required or recommended features can added to the issue or in this topic.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 28, 2022, 4:48am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/2 "2022-01-28T04:48:03Z")

</div>

@Mik Thank you very much! This feature was missing for a very long time and it will make an impact in many projects.

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [September 26, 2022, 2:27am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/3 "2022-09-26T02:27:46Z")

</div>

Hi Mik

Thank you for your development about color scalar bar

I try to plot the scalar bar on “View1” (i.e., 3D view).  
“View1” was selected in the View panel, but the color bar is not displayed in the 3D view as shown in the example above.

Is there a way to solve this problem ?

Best,

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [September 26, 2022, 9:48am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/4 "2022-09-26T09:48:12Z")

</div>

For what data are you trying to display color legend in 3D: scalar volume, model or something else? Currently there is a limitation of showing color legends in 3D.

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [September 26, 2022, 9:56am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/5 "2022-09-26T09:56:26Z")

</div>

It is scalar volume.

I made a volume rendering plot using scientific data (as colormap)  
And I would like to make color legend of this volume rendering

As far as I search, the color legend in 3D look likt only for model. Is it right?

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [September 26, 2022, 10:12am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/6 "2022-09-26T10:12:35Z")

</div>

Correct. Color legend can be shown in 3D for models.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 26, 2022, 9:24pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/7 "2022-09-26T21:24:08Z")

</div>

@Mik submitted a [pull request](https://github.com/Slicer/Slicer/pull/6550) that will allow displaying color legend of volumes shown slice views to be shown in 3D views as well. It’ll be available in the Slicer Preview Release within a few days.

> [@park](#):
>
> I made a volume rendering plot using scientific data (as colormap)  
> And I would like to make color legend of this volume rendering

If you enable “Synchronize with Volumes module” in Volume rendering module’s Advanced / Volume Properties section then the same color legend applies to volume rendering and slice views. However, if you use any other volume rendering preset then there is no GUI for making the volume rendering’s Scalar Color Mapping appear as a color legend, but you can achieve it by copy-pasting this Python script into the Python console in Slicer:

```python
# Get colormap from first volume rendering property node
colorMapOfVolumeRendering = getNode('*Prop*').GetColor()

# Add color node
colorNode = slicer.mrmlScene.CreateNodeByClass("vtkMRMLProceduralColorNode")
colorNode.UnRegister(None) # to prevent memory leaks
colorNode.SetHideFromEditors(False)
slicer.mrmlScene.AddNode(colorNode)
colorMap = colorNode.GetColorTransferFunction()
colorMap.DeepCopy(colorMapOfVolumeRendering)

# Add an empty displayable node (you can only show a color legend if it belongs to a displayable node)
displayableNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "volume")
displayableNode.CreateDefaultDisplayNodes()
displayNode = displayableNode.GetDisplayNode()

# Display color legend
displayNode.SetAndObserveColorNodeID(colorNode.GetID())
colorLegendDisplayNode = slicer.modules.colors.logic().AddDefaultColorLegendDisplayNode(displayableNode)

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/4/6407fb82f616726b2d8abcc36f9bdb93f4300925.jpeg)

@mik if you have time you might consider adding display of color legend for volume rendering (but instead of creating a separate color node, take the colormap from the volume property node). However, I’m not sure how often users want to display color legend for volume rendering.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [October 5, 2022, 3:14pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/8 "2022-10-05T15:14:53Z")

</div>

The color legend for volume rendering should be displayed only in 3D?

---

<div class="post-metadata">

**Author:** ![JulianEG](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/julianeg/32/81839_2.png) [@JulianEG](https://discourse.slicer.org/u/JulianEG)\
**Post date:** [January 26, 2026, 7:24pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/9 "2026-01-26T19:24:19Z")

</div>

@Mik I am having an issue with a module that used the old VTKScaleBar, I was wondering if you could help me to update it to Color Legend. The module is BoneThicknessMapping (version f98136b 22.02.2023).

When I try to run it, the phython console shows the following:

Traceback (most recent call last):

File “C:/Users/Asus/AppData/Local/NA-MIC/Slicer 5.2.2/NA-MIC/Extensions-31382/BoneThicknessMapping/lib/Slicer-5.2/qt-scripted-modules/BoneThicknessMapping.py”, line 521, in click\_execute

BoneThicknessMappingLogic.set\_scalar\_colour\_bar\_state(0)

File “C:/Users/Asus/AppData/Local/NA-MIC/Slicer 5.2.2/NA-MIC/Extensions-31382/BoneThicknessMapping/lib/Slicer-5.2/qt-scripted-modules/BoneThicknessMapping.py”, line 936, in set\_scalar\_colour\_bar\_state

ctkBar = slicer.util.findChildren(colorWidget, name=‘VTKScalarBar’)[0]

IndexError: list index out of range

[Qt] This function is deprecated. Use lookFromAxis(const ctkAxesWidget::Axis& axis) instead.

The section of code referenced is this (starting from line 933):

```auto
@staticmethod
def set_scalar_colour_bar_state(state, color_node_id=None):
    colorWidget = slicer.modules.colors.widgetRepresentation()
    ctkBar = slicer.util.findChildren(colorWidget, name='VTKScalarBar')[0]
    ctkBar.setDisplay(state)
    if state == 0 or color_node_id is None: return
    slicer.util.findChildren(colorWidget, 'ColorTableComboBox')[0].setCurrentNodeID(color_node_id)
    slicer.util.findChildren(colorWidget, 'UseColorNameAsLabelCheckBox')[0].setChecked(True)

```

And it is called upon in other sections such as this (lines 581 and 582):

```auto
    # update scalar bar
    BoneThicknessMappingLogic.set_scalar_colour_bar_state(1, colourNodeId)

```

Hope you can help and thank you for your time regardless!

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 29, 2026, 4:00am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/10 "2026-01-29T04:00:49Z")

</div>

Is this module BoneThicknessMapping compile and run without problems? I mean i hope it isn’t abandoned.

You just want to show color legend for a model node or volume, or you want a properly working button within the module?

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 29, 2026, 9:00am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/11 "2026-01-29T09:00:56Z")

</div>

One more question. Do you need color legend for calculated model node or for the input volume node as well?

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 29, 2026, 10:36am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/12 "2026-01-29T10:36:23Z")

</div>

I have made a [PR](https://github.com/Auditory-Biophysics-Lab/Slicer-BoneThicknessMapping/pull/8) to upgrade that module. Can you download and check that this upgrade is that what you need.

---

<div class="post-metadata">

**Author:** ![JulianEG](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/julianeg/32/81839_2.png) [@JulianEG](https://discourse.slicer.org/u/JulianEG)\
**Post date:** [January 29, 2026, 5:42pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/13 "2026-01-29T17:42:30Z")

</div>

Thank you for all your help. I ran the module with the modifications but it doesn’t seem to work. What I get on the console is the following:

* * *

Traceback (most recent call last):

File “C:/Users/Asus/AppData/Local/NA-MIC/Slicer 5.2.2/NA-MIC/Extensions-31382/BoneThicknessMapping/lib/Slicer-5.2/qt-scripted-modules/BoneThicknessMapping.py”, line 521, in click\_execute

# BoneThicknessMappingLogic.set\_scalar\_colour\_bar\_state(0)

File “C:/Users/Asus/AppData/Local/NA-MIC/Slicer 5.2.2/NA-MIC/Extensions-31382/BoneThicknessMapping/lib/Slicer-5.2/qt-scripted-modules/BoneThicknessMapping.py”, line 936, in set\_scalar\_colour\_bar\_state

colorLegendNode = slicer.modules.colors.logic().GetColorLegendDisplayNode(displayable\_node)

IndexError: list index out of range

[Qt] This function is deprecated. Use lookFromAxis(const ctkAxesWidget::Axis& axis) instead.

* * *

The IndexError persists, which makes me think that the issue is not due to the change from VTKScalarBar to ColorLegend but lies somewhere else.

This results in the progress bar when using the module not moving from 0% (status:initializing execution). The issue is the same as described on this post [BoneThicknessMapping does not work](https://discourse.slicer.org/t/bonethicknessmapping-does-not-work/30738) . This other post seems to describe the same problem and according to them it worked properly in 3dslicer 4.1.1 [Bone Thickness Mapping not functioning](https://discourse.slicer.org/t/bone-thickness-mapping-not-functioning/29453) .

Thank you anyway for your help and time.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 29, 2026, 6:04pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/14 "2026-01-29T18:04:24Z")

</div>

I’m working with Slicer-5.9. Can you check that update with a newer Slicer version rather then 5.2?

---

<div class="post-metadata">

**Author:** ![JulianEG](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/julianeg/32/81839_2.png) [@JulianEG](https://discourse.slicer.org/u/JulianEG)\
**Post date:** [January 29, 2026, 7:13pm UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/15 "2026-01-29T19:13:16Z")

</div>

It does work now! In 3D Slicer version 5.10 and using your upgrade script. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [January 30, 2026, 5:19am UTC](https://discourse.slicer.org/t/color-scalar-bar-reworked-and-upgraded-now-it-s-called-color-legend/21567/16 "2026-01-30T05:19:41Z")

</div>

If there are bugs in new color legend with displayed color table, let me know.
