# Accessing vtkScalarBarActor from Paraview/Python

**URL:** https://discourse.paraview.org/t/accessing-vtkscalarbaractor-from-paraview-python/6547
**Category:** ParaView Support
**Tags:** vtk, python
**Created:** [February 24, 2021, 3:56pm UTC](https://discourse.paraview.org/t/accessing-vtkscalarbaractor-from-paraview-python/6547 "2021-02-24T15:56:47Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![liangwang0734](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/3ab097/32.png) [@liangwang0734](https://discourse.paraview.org/u/liangwang0734)
#### Post date: [February 24, 2021, 3:56pm UTC](https://discourse.paraview.org/t/accessing-vtkscalarbaractor-from-paraview-python/6547/1 "2021-02-24T15:56:47Z")

</div>

My true motivation is to add a background color to the colorbar widget (when the rendered objects are messy and make the colorbar widget text/colors hard to see). The [pyvista package](https://github.com/pyvista/pyvista/blob/master/pyvista/plotting/plotting.py) seems to do it directly with `vtkScalarBarActor`'s `GetBackgroundProperty` method. But these are not exposed to ParaView GUI or Python.

Example (after creating a sphere source):

```python
from paraview.simple import *
from paraview import servermanager as sm

lut = GetColorTransferFunction('Normals')
renderView1 = GetActiveViewOrCreate('RenderView')

cbar_widget_repr = GetScalarBar(lut, renderView1)
# <paraview.servermanager.ScalarBarWidgetRepresentation object at 0x7f19c3b0ecd0>

# (paraview.modules.vtkRemotingViews.vtkSMScalarBarWidgetRepresentationProxy)0x7f1a25b017c0
cbar_widget_repr_proxy = cbar_widget_repr.SMProxy

# Following lines give errors like "no attribute 'GetNumberOfOutputPorts'"
sm.Fetch(cbar_widget_repr)
sm.Fetch(cbar_widget_repr_proxy)
sm.Fetch(cbar_widget_repr_proxy.GetRepresentationProxy().GetProperty('ScalarBarActor'))

```

#### Update 1:

Now I do get the `vtkScalarBarActor` and can have full control of it. But the draw background still does not show up:

```python
repr_proxy = cbar_widget_repr_proxy.GetRepresentationProxy()

actor_as_proxy_prop = repr_proxy.GetProperty('ScalarBarActor')

# paraview.modules.vtkRemotingViews.vtkContext2DScalarBarActor object!
actor = actor_as_proxy_prop.GetProxy(0).GetClientSideObject()

# vtkProperty2D object!
actor_background_props = actor.GetBackgroundProperty()

# following changes do NOT seem to change the colorbar background
actor_background_props.SetColor(0, 1, 0)
actor_background_props.SetOpacity(1)

actor.DrawBackgroundOn()

## following changes do NOT seem to show a frame
actor.DrawFrameOn()

# following title text property changes work
text_props = actor.GetTitleTextProperty()
text_props.SetBackgroundOpacity(1)
text_props.SetBackgroundColor(0.5,0.5,0.5)
text_props.SetFrame(True)

# following label text property changes work
label_props = actor.GetLabelTextProperty()
label_props.SetBackgroundColor(0.8,0.8,1)
label_props.SetBackgroundOpacity(1)

```
