# Color mesh by vector component

**URL:** https://discourse.paraview.org/t/color-mesh-by-vector-component/11356
**Category:** Web Support
**Tags:** vtk, python
**Created:** [February 8, 2023, 2:22pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356 "2023-02-08T14:22:05Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![albert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://discourse.paraview.org/u/albert)
#### Post date: [February 8, 2023, 2:22pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/1 "2023-02-08T14:22:05Z")

</div>

Hi all,

I’m trying to plot an UnstructuredGrid mesh with color based on a single vector component with trame.

The vtu is defined as follow:

```auto
<PointData Scalars="'Press'" Vectors="'U','UR'" >
<DataArray type="Float32" Name="U" NumberOfComponents="3" ComponentName0="U1" ComponentName1="U2" ComponentName2="U3" format="ascii">
0.0 0.0 0.0 
...

```

The pipeline for coloring the mesh is defined as:

```auto
def color_by_array(actor, array, component_idx):
    _min, _max = array.get("range")
    mapper = actor.GetMapper()
    mapper.SelectColorArray(array.get("main_var"))
    lut = mapper.GetLookupTable()
      
    lut.SetRange(_min, _max)
    lut.SetVectorModeToComponent()
    lut.SetVectorComponent(component_idx)
    
    if array.get("type") == vtkDataObject.FIELD_ASSOCIATION_POINTS:
      mapper.SetScalarModeToUsePointFieldData()
    else:
      mapper.SetScalarModeToUseCellFieldData()
    mapper.SetScalarVisibility(True)
    mapper.SetUseLookupTableScalarRange(True)

```

In main\_var there’s, for example, the string ‘U’.

Anyway the code seems to work only for the first component (component\_idx = 0), while it doesn’t work for different components (it changes only the range coming from the array object). Even if I use the legacy ColorByArrayComponent function I obtain the same wrong result.

Do you have any suggestion to deal with this?

Thanks

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [February 8, 2023, 3:24pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/2 "2023-02-08T15:24:47Z")

</div>

I just tried the [geometry example](https://kitware.github.io/vtk-js/examples/GeometryViewer/index.html) using  
[sphere.vtp](https://discourse.paraview.org/uploads/short-url/9p8wafMFRncru75qaxQm98Lnwws.vtp) (4.6 KB) and coloring by the various normal components and everything seems fine.

But now that I read more carefully your message, I’m realizing your code is in Python and not JS which means, you have a server and a client.

Can you specify what kind of setup you are using?

---

<div class="post-metadata">

### Author: ![albert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://discourse.paraview.org/u/albert)
#### Post date: [February 8, 2023, 3:42pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/3 "2023-02-08T15:42:45Z")

</div>

Actually i’m using Trame 2.2.6 on python 3.10.3

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [February 8, 2023, 10:33pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/4 "2023-02-08T22:33:36Z")

</div>

With the `VtkLocalView` or `VtkRemoteView`?

---

<div class="post-metadata">

### Author: ![albert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://discourse.paraview.org/u/albert)
#### Post date: [February 8, 2023, 11:38pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/5 "2023-02-08T23:38:24Z")

</div>

Actually the problem occurs with VtkLocalView. I will test also with remoteview

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [February 9, 2023, 1:05am UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/6 "2023-02-09T01:05:15Z")

</div>

The RemoteView is key to make sure your VTK server code is correct. The LocalView is still wip and is more likely to miss something. If the RemoteView works when you interact with the scene, that probably means you forget to call `update()` on your view via the controller or direct method ref.

---

<div class="post-metadata">

### Author: ![albert](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://discourse.paraview.org/u/albert)
#### Post date: [February 9, 2023, 8:55am UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/7 "2023-02-09T08:55:20Z")

</div>

RemoteView is working, thanks!  
When usingLocalView I was calling update() on my views but the SetVectorComponent seems to do nothing (only changes the color range via SetRange).  
Anyway, I can deal with RemoteView for my task. Thanks again Sebastien!

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [February 9, 2023, 3:28pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/8 "2023-02-09T15:28:01Z")

</div>

Great, thanks for the update… That means the scene serializer is missing those LUT settings and miss the propagation to the client side.

[Tracked issue here](https://github.com/Kitware/trame-vtk/issues/26)

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [March 9, 2023, 10:24pm UTC](https://discourse.paraview.org/t/color-mesh-by-vector-component/11356/9 "2023-03-09T22:24:28Z")

</div>

Should be fixed in `trame-vtk>=2.3.2`
