Unable to Obtain Surface Plot

101 views
Skip to first unread message

Radhika Prasad

unread,
Jun 30, 2019, 11:38:51 PM6/30/19
to pyqtgraph
I have tried using the pyqtgraph surface plot example for obtaining a surface plot. Unfortunately, nothing appears. Please help.
Even in the example code, if I comment out everything else except for the saddle surface plot, then also nothing appears.

Here is the code:

from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import numpy as np

## Create a GL View widget to display data
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
#w.setCameraPosition(distance=50)

g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10)  # draw grid after surfaces since they may be translucent
w.addItem(g)

x = np.linspace(-8, 8, 50)
y = np.linspace(-8, 8, 50)
#z = np.exp((-x.reshape(50,1) ** 2) - (y.reshape(1,50) ** 2))
z = x.reshape(50,1)+y.reshape(1,50)
p = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader='normalColor')
#p2.translate(-10,-10,0)
w.addItem(p)


vas...@gmail.com

unread,
Jun 30, 2019, 11:58:31 PM6/30/19
to pyqt...@googlegroups.com
Add to end of your code:

while w.isVisible():
    app.processEvents()

That's all,
Vasilije



--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/43710773-a836-427a-816a-fa36ab2cc507%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Radhika Prasad

unread,
Jul 3, 2019, 7:05:36 AM7/3/19
to pyqtgraph
Thanks. It works.
Just curious: This command is not mentioned in the documentation so how does one learn more about it?
To unsubscribe from this group and stop receiving emails from it, send an email to pyqt...@googlegroups.com.

Carlos Pascual

unread,
Jul 3, 2019, 11:36:40 AM7/3/19
to pyqt...@googlegroups.com, Radhika Prasad
processEvents is a QCoreApplication method documented here:

https://doc.qt.io/qt-5/qcoreapplication.html#processEvents
+----------------------------------------------------+
Carlos Pascual Izarra
Scientific Software Coordinator
Computing Division
ALBA Synchrotron [http://www.albasynchrotron.es]
Carrer de la Llum 2-26
E-08290 Cerdanyola del Valles (Barcelona), Spain
E-mail: cpas...@cells.es
Phone: +34 93 592 4428
+----------------------------------------------------+

vas...@gmail.com

unread,
Jul 3, 2019, 3:17:01 PM7/3/19
to pyqt...@googlegroups.com
Other way to make your app working is to add:

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

to the end of your code.

That's way is mentioned in most of the examples http://www.pyqtgraph.org/downloads/0.10.0/pyqtgraph-0.10.0-deb/pyqtgraph-0.10.0/examples/, but I think that is easier for start to have your own while loop instead to use update() function as in some examples.

To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/096bc9d0-dba1-45ba-9db0-2b8c04386772%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages