[vtkusers] vtkChartLegend Position in Python
Slaughter, Andrew E
andrew.slaughter at inl.gov
Thu Oct 8 14:33:39 EDT 2015
I am writing a script to build some line charts in VTK, but I am having
difficulty repositioning a vtkChartLegend object.
The python script below will create a plot. I would like to reposition the
legend to the upper left-hand side of the chart so as to not interfere with
the line plot. However, I am not able to make the legend move. I would
appreciate any help to get the legend to re-position?
I am running OSX (Yosemite) with Python 2.7.6 and VTK 6.3.
#!/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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151008/814aaa6c/attachment.html>
More information about the vtkusers
mailing list