<div dir="ltr"><div>Hi Andrew,</div><div><br></div>Have you tried vtkChartXY::SetLegendPosition(const vtkRectf & rect), e.g.<div><br></div><div>rect = vtkRectf(0, 20, ?, ?)</div><div>char.SetLegendPosition(rect)</div><div><br></div><div>HTH,</div><div>Cory</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 8, 2015 at 2:33 PM, Slaughter, Andrew E <span dir="ltr"><<a href="mailto:andrew.slaughter@inl.gov" target="_blank">andrew.slaughter@inl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:19.5px">I am writing a script to build some line charts in VTK, but I am having difficulty repositioning a vtkChartLegend object.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:19.5px">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?</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:19.5px">I am running OSX (Yosemite) with Python 2.7.6 and VTK 6.3.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:19.5px"><br></p><span style="font-size:12.8px">#!/usr/bin/env python</span><br style="font-size:12.8px"><span style="font-size:12.8px">import vtk</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Num. points</span><br style="font-size:12.8px"><span style="font-size:12.8px">n = 10</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Create some data</span><br style="font-size:12.8px"><span style="font-size:12.8px">x = vtk.vtkFloatArray()</span><br style="font-size:12.8px"><span style="font-size:12.8px">y = vtk.vtkFloatArray()</span><br style="font-size:12.8px"><span style="font-size:12.8px">x.SetNumberOfTuples(n)</span><br style="font-size:12.8px"><span style="font-size:12.8px">x.SetName('x')</span><br style="font-size:12.8px"><span style="font-size:12.8px">y.SetNumberOfTuples(n)</span><br style="font-size:12.8px"><span style="font-size:12.8px">y.SetName('y')</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">for i in range(10):</span><br style="font-size:12.8px"><span style="font-size:12.8px"> x.SetValue(i, float(i))</span><br style="font-size:12.8px"><span style="font-size:12.8px"> y.SetValue(i, float(2*i))</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Create the table and line</span><br style="font-size:12.8px"><span style="font-size:12.8px">table = vtk.vtkTable()</span><br style="font-size:12.8px"><span style="font-size:12.8px">table.AddColumn(x)</span><br style="font-size:12.8px"><span style="font-size:12.8px">table.AddColumn(y)</span><br style="font-size:12.8px"><span style="font-size:12.8px">line = vtk.vtkPlotLine()</span><br style="font-size:12.8px"><span style="font-size:12.8px">line.SetInputData(table, 0, 1)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Create chart</span><br style="font-size:12.8px"><span style="font-size:12.8px">chart = vtk.vtkChartXY()</span><br style="font-size:12.8px"><span style="font-size:12.8px">chart.AddPlot(line)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Create view</span><br style="font-size:12.8px"><span style="font-size:12.8px">view = vtk.vtkContextActor()</span><br style="font-size:12.8px"><span style="font-size:12.8px">view.GetScene().AddItem(chart)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Renderer</span><br style="font-size:12.8px"><span style="font-size:12.8px">renderer = vtk.vtkRenderer()</span><br style="font-size:12.8px"><span style="font-size:12.8px">renderer.SetBackground(1,1,1)</span><br style="font-size:12.8px"><span style="font-size:12.8px">renderer.AddViewProp(view)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Legend</span><br style="font-size:12.8px"><span style="font-size:12.8px">chart.SetShowLegend(True)</span><br style="font-size:12.8px"><span style="font-size:12.8px">legend = chart.GetLegend()</span><br style="font-size:12.8px"><span style="font-size:12.8px">legend.SetPoint(0, 20) # This doesn't seem to do anything</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Window</span><br style="font-size:12.8px"><span style="font-size:12.8px">window = vtk.vtkRenderWindow()</span><br style="font-size:12.8px"><span style="font-size:12.8px">window.AddRenderer(renderer)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Interactor</span><br style="font-size:12.8px"><span style="font-size:12.8px">interactor = vtk.vtkRenderWindowInteractor(</span><span style="font-size:12.8px">)</span><br style="font-size:12.8px"><span style="font-size:12.8px">interactor.SetRenderWindow(</span><span style="font-size:12.8px">window)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"># Render</span><br style="font-size:12.8px"><span style="font-size:12.8px">window.Render()</span><br style="font-size:12.8px"><span style="font-size:12.8px">renderer.Render()</span><br style="font-size:12.8px"><span style="font-size:12.8px">interactor.Start()</span><br></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>