[vtkusers] vtkChartXY, QVTKRenderWindowInteractor, PyQt4
Randy Heiland
heiland at indiana.edu
Tue Jul 26 12:08:00 EDT 2011
Duh. To answer my own question, one must manually set axes labels, e.g.:
chart.GetAxis(vtkAxis.LEFT).SetTitle()
On Jul 23, 2011, at 8:07 AM, Randy Heiland wrote:
> If I change the names (SetName) of the arrays, the axes labels on the rendered chart do not change, i.e. they're still "X Axis", "Y Axis". Suggestions?
>
>>>> print vtk.vtkVersion.GetVTKVersion()
> 5.9.0
>
> thanks, Randy
>
> On Jul 22, 2011, at 10:51 PM, Randy Heiland wrote:
>
>> For the archive, the following seems to do what I need (until it doesn't):
>>
>> # ------- gui-chart.py ------------
>> import sys
>> from vtk import *
>> from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
>> from PyQt4 import Qt
>> from PyQt4 import QtGui
>>
>> class test(Qt.QMainWindow):
>> def __init__(self, parent=None):
>> Qt.QMainWindow.__init__(self, parent)
>> self.setWindowTitle(self.tr("PyQt4 vtkChartXY"))
>> self.workspace = Qt.QWorkspace()
>> self.setCentralWidget(self.workspace)
>> self.frame = QtGui.QFrame(self.workspace)
>> self.hbox = QtGui.QHBoxLayout()
>>
>> self.widget = QVTKRenderWindowInteractor(self.frame)
>> self.widget.Initialize()
>> self.widget.Start()
>>
>> self.table = vtkTable()
>> self.arrX = vtkFloatArray()
>> self.arrX.SetName("X Axis")
>> self.table.AddColumn(self.arrX)
>>
>> self.arrY = vtkFloatArray()
>> self.arrY.SetName("Y value")
>> self.table.AddColumn(self.arrY)
>>
>> numPoints = 20
>> inc = 7.5 / (numPoints-1)
>> self.table.SetNumberOfRows(numPoints)
>> for i in range(numPoints):
>> self.table.SetValue(i, 0, i * inc)
>> self.table.SetValue(i, 1, i * inc)
>>
>> self.view = vtkContextView()
>> self.view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
>>
>> self.chart = vtkChartXY()
>> self.view.GetScene().AddItem(self.chart)
>> self.line = self.chart.AddPlot(vtkChart.LINE)
>> self.line.SetInput(self.table, 0, 1)
>>
>> self.ren = self.view.GetRenderer()
>> self.renWin = self.widget.GetRenderWindow()
>> self.renWin.AddRenderer(self.ren)
>>
>> self.hbox.addWidget(self.widget)
>> self.frame.setLayout(self.hbox)
>> self.workspace.addWindow(self.frame)
>>
>> if __name__ == "__main__":
>> app = Qt.QApplication(sys.argv)
>> mainwindow = test()
>> mainwindow.show()
>> sys.exit(app.exec_())
>>
>> On Jul 22, 2011, at 5:47 PM, Randy Heiland wrote:
>>
>>> Hi gang,
>>>
>>> I'm having problems getting a vtkChartXY displayed in PyQt4. I saw a thread related to this (vtkContextView and QWidget), but didn't see a solution for Python-land. I'll include 2 example scripts - the 1st works, the 2nd does not.
>>>
>>> thanks for any help, Randy
>>> <snip>
>>
>
More information about the vtkusers
mailing list