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):
>
> On Fri, Jun 14, 2013 at 3:58 AM, Diego Garcia <[email protected] 
> <javascript:>> 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
>
>
>
>

-- 
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/a58886b6-13b4-48ea-a308-e69364c0d2e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to