[vtkusers] vtkChartLegend Position in Python

Cory Quammen cory.quammen at kitware.com
Thu Oct 8 14:45:43 EDT 2015


Hi Andrew,

Have you tried vtkChartXY::SetLegendPosition(const vtkRectf & rect), e.g.

rect = vtkRectf(0, 20, ?, ?)
char.SetLegendPosition(rect)

HTH,
Cory

On Thu, Oct 8, 2015 at 2:33 PM, Slaughter, Andrew E <
andrew.slaughter at inl.gov> wrote:

> 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()
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151008/73259d72/attachment.html>


More information about the vtkusers mailing list