Is there an equivalent to PColor in PyQtGraph?

624 views
Skip to first unread message

Qwerty Keyboard

unread,
Feb 17, 2014, 4:38:22 PM2/17/14
to pyqt...@googlegroups.com
Hello World!

I'm basically porting a series of Matlab scripts to python, and one of them makes heavy use of Matlab's PColor function for plotting.  I've successfully implemented the same functionality with Matplotlib, but it isn't doing exactly what I want it to do.  I discovered PyQtGraph recently and I was wondering if there is an equivalent function I could use to replace the Matplotlib plots I've generated?

For those who aren't familiar with PColor, the basic idea behind it is that you give it 3 matrices, [X,Y,C].  X and Y describe vertices of polygons to draw, and C holds the color to fill the polygon with.  I'm using radar data and my arrays are quite large ( greater than 100,000 elements in some cases ), so speed is of the essence for me.  Hence my desire to use PyQtGraph if possible.

Thanks for your help.

Luke Campagnola

unread,
Feb 18, 2014, 3:54:03 AM2/18/14
to pyqt...@googlegroups.com

You can use GLMeshItem to draw the polygons, and the 'vertexColors' argument to MeshData.__init__ to set the colors properly. It would look something like:

    import pyqtgraph.opengl as gl
    md = gl.MeshData(vertexes=[...], faces=[...], vertexColors=[...])
    mesh = gl.GLMeshItem(meshdata=md)
    view = gl.GLViewWidget()
    view.addItem(mesh)

You can see examples/GLMeshItem.py for a little more help.
Is this what you are looking for?

Luke Carroll

unread,
Aug 15, 2018, 3:43:11 PM8/15/18
to pyqtgraph
Hey I'm not sure if I'm posting correctly on here or if this thread is active anymore. 

When I tried running your example as a Python script I received the error:
"QWidget: Must construct a QApplication before a QWidget".

If anyone know how to construct a simple example that can produce a pcolor-like result in pyqtgraph that would be greatly appreciated. As an example, the script below can be ran on its own using Python 3.6 numpy 1.14 and matplotlib 2.2 to produce the image example pcolor_plot.png

import numpy as np
import matplotlib.pyplot as plt

x = np.array([[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4],[5,5,5,5]])
y = np.array([[4,8,12,16],[2,4,6,8],[3,6,9,12],[5,10,15,20],[6,12,18,24]])
z = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]])

plt.pcolor(x, y, z)
plt.show()

example_pcolor_plot.png

Reply all
Reply to author
Forward
0 new messages