Dear Alejandro,
Many thanks! I use almost the same setup (Spyder 3.2.4, Python 3.5.2
64bits, PyQt5.6 on Windows)
Small thing: "import sys" is missing, I guess.
I tried your code and it seems clear to me, except one point, but I
probably miss a bit of background:
you define "plotexample" as a method in the "MyWindowClass". And run it in
the constructor (well _init__).
When I try to execute then Spyder prompts "undifined name 'plotexample' ".
so I took it out and I am not sure where to call it from here...
Everything else works nicely.
I had to adapt the execution part, otherwise every second run of the
program kills the kernel:
from PyQt5 import uic,QtWidgets,QtGui
import pyqtgraph
import numpy as np
import sys
form_class = uic.loadUiType("Test_Average-GUI.ui")[0]
class MyWindowClass(QtWidgets.QMainWindow,form_class):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
# here you can properties of your graph widget.... for example:
self.GraphWidgetName.setTitle('My Graph')
self.GraphWidgetName.setLabel('bottom', 'X axis')
self.GraphWidgetName.setLabel('left', 'Y axis')
def plotexample(self):
a=np.array([1,2,3,4,5])
b=np.array([6,7,8,9,10])
self.GraphWidgetName.plot(a,b)
self.GraphWidgetName.showGrid(x=True, y=True)
if __name__=="__main__":
app = QtWidgets.QApplication.instance() #Check for an instance of a
QtWidgets.QApplication, if so use it...
if app is None:
app = QtWidgets.QApplication(sys.argv)
else:
print('QApplication instance already exists: %s' % str(app))
MyWindow = MyWindowClass(None)
MyWindow.show()
app.exec_()
Am Sonntag, 22. Oktober 2017 22:19:49 UTC+2 schrieb Alejandro Condori:
>
> I use Spyder (from Anaconda)(Python 3.6 and PyQt5). Try to run something
> like this:
>
> from PyQt5 import uic,QtWidgets,QtGui
> import numpy as np
>
> form_class = uic.loadUiType("yourUIfile.ui")[0]
>
> class MyWindowClass(QtWidgets.QMainWindow,form_class):
> def __init__(self, parent=None):
> QtWidgets.QMainWindow.__init__(self, parent)
> self.setupUi(self)
> # here you can properties of your graph widget.... for example:
> self.GraphWidgetName.setTitle('My Graph')
> self.GraphWidgetName.setLabel('bottom', 'X axis')
> self.GraphWidgetName.setLabel('left', 'Y axis')
> plotexample()
>
>
> def plotexample(self):
> a=np.array([1,2,3,4,5])
> b=np.array([6,7,8,9,10])
> self.GraphWidgetName.plot(a,b)
> self.GraphWidgetName.showGrid(x=True, y=True)
>
> if __name__=="__main__":
> app = QtWidgets.QApplication(sys.argv)
> MyWindow = MyWindowClass(None)
> MyWindow.show()
> app.exec_()
>
> I made this right now, please try it and tell me if this works for you,
> dont forget to change the name like "yourUIfile.ui" for the names of the
> files you have. In my case i didn't have to import pyqtgraph library
> because the widget already have the properties of pyqtgraph (this only if
> you promoted QGraphicsView Widget correctly). Well if this dont works try
> adding "import pyqtgraph" at the start of the script. Good Luck...
>
> Alejandro
> PD: English is not my mother language, i hope you will understand what i
> wrote.
>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/f1aa12e3-2178-4f2d-863d-985959ee572b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.