bargraph ?

138 views
Skip to first unread message

Stef Mientki

unread,
Feb 16, 2013, 7:02:41 PM2/16/13
to pyqt...@googlegroups.com
hello,

did anyone created a bargraph in pyqtgraph ?

thanks,
Stef

Luke Campagnola

unread,
Mar 27, 2013, 8:23:15 PM3/27/13
to pyqt...@googlegroups.com
On Sat, Feb 16, 2013 at 7:02 PM, Stef Mientki <stef.m...@gmail.com> wrote:
hello,

did anyone created a bargraph in pyqtgraph ?

Stef Mientki

unread,
Mar 28, 2013, 7:52:39 PM3/28/13
to pyqt...@googlegroups.com
thanks very much Luke,
that's great news !!

cheers,
Stef

Luke 

--
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
---
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Diego Garcia

unread,
Jun 14, 2013, 3:58:07 AM6/14/13
to pyqt...@googlegroups.com
Will be added 3D bars in the next release too? like matplotlib http://imageshack.us/photo/my-images/831/histogramsample.png/

They are very useful!

Thank you

Luke Campagnola

unread,
Jun 14, 2013, 9:27:39 AM6/14/13
to pyqt...@googlegroups.com
On Fri, Jun 14, 2013 at 3:58 AM, Diego Garcia <koby...@gmail.com> wrote:
Will be added 3D bars in the next release too? like matplotlib http://imageshack.us/photo/my-images/831/histogramsample.png/


Here's a very simple implementation:

from GLMeshItem import GLMeshItem
from ..MeshData import MeshData
import numpy as np

class GLBarGraphItem(GLMeshItem):
    def __init__(self, pos, size):
        """
        pos is (...,3) array of the bar positions (the corner of each bar)
        size is (...,3) array of the sizes of each bar
        """
        nCubes = reduce(lambda a,b: a*b, pos.shape[:-1])
        cubeVerts = np.mgrid[0:2,0:2,0:2].reshape(3,8).transpose().reshape(1,8,3)
        cubeFaces = np.array([
            [0,1,2], [3,2,1],
            [4,5,6], [7,6,5],
            [0,1,4], [5,4,1],
            [2,3,6], [7,6,3],
            [0,2,4], [6,4,2],
            [1,3,5], [7,5,3]]).reshape(1,12,3)
        size = size.reshape((nCubes, 1, 3))
        pos = pos.reshape((nCubes, 1, 3))
        verts = cubeVerts * size + pos
        faces = cubeFaces + (np.arange(nCubes) * 8).reshape(nCubes,1,1)
        md = MeshData(verts.reshape(nCubes*8,3), faces.reshape(nCubes*12,3))
        
        GLMeshItem.__init__(self, meshdata=md, shader='shaded', smooth=False)

It isn't perfect and isn't really good enough to be included in the library, but it's a good starting point to improve on.
Here's an example of how to use it:

# regular grid of starting positions
pos = np.mgrid[0:10, 0:10, 0:1].reshape(3,10,10).transpose(1,2,0)

# fixed widths, random heights
size = np.empty((10,10,3))
size[...,0:2] = 0.4
size[...,2] = np.random.normal(size=(10,10))

bg = gl.GLBarGraphItem(pos, size)

I presume you are already familiar with the OpenGL graphics system in pyqtgraph. If not, look through the GL* examples.


Luke



Jiri Ch

unread,
Apr 23, 2018, 7:03:55 AM4/23/18
to pyqtgraph
Hi Luke,

is there any progress there (plotting 3D bar charts)? Thanks

Jiri

Dne pátek 14. června 2013 15:27:39 UTC+2 Luke Campagnola napsal(a):
Reply all
Reply to author
Forward
0 new messages