# Colorbar of volume rendering on 3D view

**URL:** <https://discourse.slicer.org/t/colorbar-of-volume-rendering-on-3d-view/25336>\
**Category:** Support\
**Created:** [September 19, 2022, 11:10am UTC](https://discourse.slicer.org/t/colorbar-of-volume-rendering-on-3d-view/25336 "2022-09-19T11:10:12Z")\
**Posts on this page:** 2\
**Page:** 1

<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 19, 2022, 11:10am UTC](https://discourse.slicer.org/t/colorbar-of-volume-rendering-on-3d-view/25336/1 "2022-09-19T11:10:12Z")

</div>

Hellow all,

I would like to make color bar of volume rendering plot on 3D view  
The volume rendering function is costum maded for scientific data  
(The code indicated below)

Is there any way to make this ?

```auto
def showVolumeRendering(volumeNode):

    volRenLogic = slicer.modules.volumerendering.logic()
    displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode)

    propertyNode = displayNode.GetVolumePropertyNode()

    VolumeProperty = propertyNode.GetVolumeProperty()
    VolumeProperty.SetAmbient(0.95)
    VolumeProperty.SetDiffuse(0.15)
    VolumeProperty.SetSpecular(0.0)
    VolumeProperty.SetSpecularPower(1.0)

    array = slicer.util.arrayFromVolume(volumeNode)
    array_max = np.max(array)

    opacityTransfer = vtk.vtkPiecewiseFunction()
    opacityTransfer.AddPoint(0,0)
    opacityTransfer.AddPoint(array_max*0.15, 0.)
    opacityTransfer.AddPoint(array_max*0.3,0.07)
    opacityTransfer.AddPoint(array_max*0.5,0.07)
    opacityTransfer.AddPoint(array_max*0.6,0.07)
    opacityTransfer.AddPoint(array_max*0.7,0.1)
    opacityTransfer.AddPoint(array_max*0.85,0.35)
    opacityTransfer.AddPoint(array_max*0.99,1)
    opacityTransfer.AddPoint(array_max*1,0.01)

    ctf = vtk.vtkColorTransferFunction()
    ctf.AddRGBPoint(array_max*0.25, 0.1,0.1,1.0)
    ctf.AddRGBPoint(array_max*0.5, 0.2,1.0,0.2)
    ctf.AddRGBPoint(array_max*0.75, 1.0,0.5,0.0)
    ctf.AddRGBPoint(array_max*0.95, 1.0,0.0,0.0)

    propertyNode.SetColor(ctf)
    propertyNode.SetScalarOpacity(opacityTransfer)

```

---

<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 19, 2022, 1:59pm UTC](https://discourse.slicer.org/t/colorbar-of-volume-rendering-on-3d-view/25336/2 "2022-09-19T13:59:00Z")

</div>

See how to do this in [examples in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#create-custom-color-map-and-display-color-legend).
