我正在编写一个脚本来在VTK中构建一些折线图,但是我很难重新定位vtkChartLegend对象。
下面的python脚本将创建显示的图表。我想将图例重新定位到图表的左上角,以免干扰线图。但是,我无法使传奇动人。我很感激任何帮助让传奇重新定位?
我正在使用Python 2.7.6和VTK 6.3运行OSX(Yosemite)。
#!/usr/bin/env python
import vtk
# Num. points
n = 10
# Create some data
x = vtk.vtkFloatArray()
y = vtk.vtkFloatArray()
x.SetNumberOfTuples(n)
x.SetName('x')
y.SetNumberOfTuples(n)
y.SetName('y')
for i in range(10):
x.SetValue(i, float(i))
y.SetValue(i, float(2*i))
# Create the table and line
table = vtk.vtkTable()
table.AddColumn(x)
table.AddColumn(y)
line = vtk.vtkPlotLine()
line.SetInputData(table, 0, 1)
# Create chart
chart = vtk.vtkChartXY()
chart.AddPlot(line)
# Create view
view = vtk.vtkContextActor()
view.GetScene().AddItem(chart)
# Renderer
renderer = vtk.vtkRenderer()
renderer.SetBackground(1,1,1)
renderer.AddViewProp(view)
# Legend
chart.SetShowLegend(True)
legend = chart.GetLegend()
legend.SetPoint(0, 20) # This doesn't seem to do anything
# Window
window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
# Interactor
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
# Render
window.Render()
renderer.Render()
interactor.Start()
答案 0 :(得分:0)
我收到了vtkusers邮件列表的回复,解决了我的问题。
legend.SetHorizontalAlignment(vtk.vtkChartLegend.CUSTOM)
legend.SetVerticalAlignment(vtk.vtkChartLegend.CUSTOM)
legend.SetPoint(200, 200) # position in window coordinates