How to let vtkScalarBar showing marks for Text Annotation?

Dear Vtk Experts,

I am trying to add to a vtkScalarbar tick marks in order to link TextAnnotation objects to actual value in colorbar.

I tried in python by using

lab.color = (0,0,0)

pp = sc.trait_get('_vtk_obj')['_vtk_obj']

pp.FixedAnnotationLeaderLineColorOn()

but this is not helping.

Looking forward to hearing from you.

Gabriele

I didn’t understand your question, but I can give you a C++ code I used in the past to display the labels :

void MyColorMap::SetupScalarBar()
{
    m_scalarBarActor->SetLookupTable(m_colorManager->GetLookupTable());
    m_scalarBarActor->SetNumberOfLabels(6); // <<=========
    m_scalarBarActor->SetWidth(0.03);
    m_scalarBarActor->SetTitle("........");

    m_scalarBarActor->GetTitleTextProperty()->SetVerticalJustificationToCentered();
    //m_scalarBarActor->GetTitleTextProperty()->SetOrientation(90.);

    m_scalarBarActor->SetPosition(0.95, 0.1);
    m_renderer->AddActor2D(m_scalarBarActor.GetPointer());
} 

Otherwise, there’s this VTK class : vtkChartHistogram2D that is, IMHO, a better solution to display a 2D spectrogram (or color map) and that has a builtin scalar bar, I don’t know if a Python wrapping exist for this last (and you will have to use the VTK that is in the gitlab master branch, as recently I fixed nasty bugs in it).

Thanks for you reply.

What I meant was that I’d like to add visible ticks (i.e. a straight line pointing from label to color) to text in scalarColorBar to help correct interpretation of actual values from color bar. There is this LeaderLineColor method that according to the documentation should do what I want to perform, but nothing is displayed. I know that this should be possible ( e.g. Paraview project which uses VTK has those nice color bars)

I hope to have clarified further my question.

is there an example in this page : https://www.paraview.org/Wiki/Beginning_ParaView of what you want to do ?

as you can see in the link provided, color scales have ticks close to their numbers. I am using Pysurfer to display some results (example: https://pysurfer.github.io/auto_examples/plot_fmri_activation_volume.html#sphx-glr-auto-examples-plot-fmri-activation-volume-py). As you can see in the example of Pysurfer, color bars doesn’t have tick marks for each label/number. The color bar is a vtkscalarColorBar object. It might be that the object used is not suited for what I am trying to achieve .

all the best,

I take a look to the C++ source code of vtkScalarBarActor (VTK) and vtkPVScalarBarActor (ParaView, which inherits from vtkScalarBarActor), and the feature you want exists only in ParaView, where the ticks marks are created with a vtkActor2D (TickMarksActor), a mapper (vtkPolyDataMapper2D) and a poly data (vtkPolyData).

One with enough free time and will can add this feature in vtkScalarBarActor from vtkPVScalarBarActor (it is not very hard) and creates a Python wrapper.

1 Like