Results 1 to 1 of 1

Thread: PyQT and Qwt read data and plot -- not able to plot

  1. #1
    Join Date
    Aug 2014
    Posts
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: PyQT and Qwt read data and plot -- not able to plot

    Dear all,
    I am new in this forum and I am also new in the PyQT-QT-Qwt environment.
    I am trying to write a program in PyQT and Qwt that should read the data from a file ant then plot it.
    Unfortunately the pram does not work and I don't know why.

    This is my code:
    There is a button (pushButton_1) that open a folder where I can select a file.
    The button pushButton_1 calls the def showDialog(self): action that open the folder and then plot the data. This is the point, I am not able to plot the data.

    This is my full code. It is no so long, so I post the entire code. I hope that is OK for the administrator.

    Qt Code:
    1. import numpy as np
    2. from PyQt4 import QtCore, QtGui
    3. import PyQt4.Qwt5 as Qwt
    4. import sys, os, csv
    5. from PyQt4.QtCore import *
    6. from PyQt4.QtGui import *
    7. import random
    8.  
    9.  
    10. try:
    11. _fromUtf8 = QtCore.QString.fromUtf8
    12. except AttributeError:
    13. def _fromUtf8(s):
    14. return s
    15.  
    16. try:
    17. _encoding = QtGui.QApplication.UnicodeUTF8
    18. def _translate(context, text, disambig):
    19. return QtGui.QApplication.translate(context, text, disambig, _encoding)
    20. except AttributeError:
    21. def _translate(context, text, disambig):
    22. return QtGui.QApplication.translate(context, text, disambig)
    23.  
    24. class Ui_MainWindow(QtGui.QMainWindow):
    25. def setupUi(self, MainWindow):
    26. MainWindow.setObjectName(_fromUtf8("MainWindow"))
    27. MainWindow.resize(800, 663)
    28. self.centralwidget = QtGui.QWidget(MainWindow)
    29. self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
    30.  
    31.  
    32.  
    33. self.pushButton_1 = QtGui.QPushButton(self.centralwidget)
    34. self.pushButton_1.setGeometry(QtCore.QRect(60, 20, 311, 27))
    35. self.pushButton_1.setObjectName(_fromUtf8("pushButton_1"))
    36. self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
    37. self.pushButton_2.setGeometry(QtCore.QRect(60, 70, 311, 27))
    38. self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
    39.  
    40.  
    41.  
    42. self.qwtPlot_2 = Qwt.QwtPlot(self.centralwidget)
    43. self.qwtPlot_2.setGeometry(QtCore.QRect(60, 170, 400, 200))
    44. self.qwtPlot_2.setObjectName(_fromUtf8("qwtPlot_2"))
    45. self.qwtPlot_2.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->')
    46. self.qwtPlot_2.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->')
    47. grid = Qwt.QwtPlotGrid()
    48. pen = QPen(Qt.DotLine)
    49. pen.setColor(Qt.black)
    50. pen.setWidth(0)
    51. grid.setPen(pen)
    52. grid.attach(self.qwtPlot_2)
    53.  
    54. self.qwtPlot_3 = Qwt.QwtPlot(self.centralwidget)
    55. self.qwtPlot_3.setGeometry(QtCore.QRect(60, 390, 400, 200))
    56. self.qwtPlot_3.setObjectName(_fromUtf8("qwtPlot_3"))
    57. self.qwtPlot_3.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->')
    58. self.qwtPlot_3.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->')
    59. grid = Qwt.QwtPlotGrid()
    60. pen = QPen(Qt.DotLine)
    61. pen.setColor(Qt.black)
    62. pen.setWidth(0)
    63. grid.setPen(pen)
    64. grid.attach(self.qwtPlot_3)
    65.  
    66. MainWindow.setCentralWidget(self.centralwidget)
    67. self.menubar = QtGui.QMenuBar(MainWindow)
    68. self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25))
    69. self.menubar.setObjectName(_fromUtf8("menubar"))
    70. MainWindow.setMenuBar(self.menubar)
    71. self.statusbar = QtGui.QStatusBar(MainWindow)
    72. self.statusbar.setObjectName(_fromUtf8("statusbar"))
    73. MainWindow.setStatusBar(self.statusbar)
    74.  
    75. self.retranslateUi(MainWindow)
    76. QtCore.QMetaObject.connectSlotsByName(MainWindow)
    77.  
    78.  
    79. self.centralwidget.connect(self.pushButton_1, QtCore.SIGNAL('clicked()'), self.showDialog)
    80.  
    81.  
    82.  
    83. def retranslateUi(self, MainWindow):
    84. MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
    85. self.pushButton_1.setText(_translate("MainWindow", "Selec file txt", None))
    86. self.pushButton_2.setText(_translate("MainWindow", "Plot", None))
    87.  
    88. #------------------------------------------------------------------------
    89. #azione apertura file0
    90. #------------------------------------------------------------------------
    91. def showDialog(self):
    92. fname = QtGui.QFileDialog.getOpenFileName(self, 'Open a data file', '.', 'txt files (*.txt);;All Files (*.*)')
    93. f = open(fname, 'r')
    94. with f:
    95. data = np.genfromtxt(f, skiprows=1)
    96. self.tdata = data[:,0]
    97. self.cdata = data[:,1]
    98. curve=Qwt.QwtPlotCurve('ciao')
    99. curve.setData(range(len(self.tdata)), self.tdata)
    100. curve.attach(self.qwtPlot_3)
    101. print 'hello'
    102. #
    103. if __name__ == "__main__":
    104. import sys
    105. app = QtGui.QApplication(sys.argv)
    106. MainWindow = QtGui.QMainWindow()
    107. ui = Ui_MainWindow()
    108. ui.setupUi(MainWindow)
    109. MainWindow.show()
    110. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance to all

    Dear all,
    I have understood why:

    I have missed the replot-one:
    Qt Code:
    1. curve = Qwt.QwtPlotCurve('Q')
    2. curve.attach(self.qwtPlot_2)
    3. curve.setPen(Qt.QPen(Qt.Qt.blue, 2))
    4. curve.setData(self.tdata, self.cdata)
    5. self.qwtPlot_2.replot()
    To copy to clipboard, switch view to plain text mode 

    thanks to all and sorry for your time
    Last edited by diedro; 1st August 2014 at 16:29.

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2013, 07:18
  2. Replies: 1
    Last Post: 17th April 2012, 11:10
  3. Replies: 9
    Last Post: 23rd December 2011, 16:56
  4. 2D array data plot!
    By kahramonj in forum Qwt
    Replies: 3
    Last Post: 21st March 2009, 12:48
  5. Replies: 7
    Last Post: 22nd September 2008, 23:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.