我正在使用 vtkLegendBoxActor 在情节中显示图例。但是,我无法控制图例中文本的字体大小。 我尝试了以下方法:
legendActor=vtkLegendBoxActor()
textProp=vtkTextProperty()
textProp.SetFontSize(3)
textProp.SetVerticalJustificationToCentered()
legendActor.SetEntryTextProperty(textProp)
不过,这个好像没有设置文字的字体大小。它仍然显示默认大小12。我在将属性设置为后检查了字体大小:
legendActor.GetEntryTextProperty().GetFontSize()
返回 3。请帮我解决这个问题。
谢谢。
一个原因可能是
vtkLegendBoxActor
出于性能原因缓存文本属性。所以需要在设置text属性后调用方法Modified()
使缓存失效
legendActor = vtkLegendBoxActor()
textProp = vtkTextProperty()
textProp.SetFontSize(3)
textProp.SetVerticalJustificationToCentered()
legendActor.SetEntryTextProperty(textProp)
legendActor.Modified() # Invalidate the cache