How to set the font size for vtkLegendScaleActor

I want to use the vtkLegendScaleActor in my project, but I can not find a way to set the font size.

I have tested:

legendScaleActor.GetLegendLabelProperty().SetFontSize(20)
legendScaleActor.GetLeftAxis().GetLabelTextProperty().SetFontSize(20)

And they don’t help.

I hope to set the font size in the following region:

image

The complete code is:

import vtk

renderWindow = vtk.vtkRenderWindow()
renderer = vtk.vtkRenderer()
renderWindow.AddRenderer(renderer)

cubeSource = vtk.vtkCubeSource()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cubeSource.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer.AddActor(actor)


legendScaleActor = vtk.vtkLegendScaleActor()

legendScaleActor.GetLegendLabelProperty().SetFontSize(20)
legendScaleActor.GetLeftAxis().GetLabelTextProperty().SetFontSize(20)

renderer.AddActor(legendScaleActor)


renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindow.Render()
renderWindowInteractor.Start()

My vtk version is 9.2.6.

Any help is appreciated~~~

I find legendScaleActor.GetLeftAxis().SetFontFactor(2) works.

1 Like

@nicolas.vuaille

Hi,

To configure font size from property, you should call UseFontSizeFromPropertyOn() on the axis (flag is off by default)

Unfortunately, this has effect only on the axis title in VTK 9.2.6. The next release will add support for tick labels (this was added in master branch a few days ago only), and a utility method to do that directly from the vtkLegendScaleActor