Reputation: 717
My goal is to create stacked 3d bar plot, for that, I am trying to change color of GlBarGraphItem from PYQTgraph library.
Here is my code:
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import numpy as np
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 100
w.showMaximized()
w.setWindowTitle('pyqtgraph example: GLViewWidget')
ax = gl.GLAxisItem()
ax.setSize(20,20,20)
w.addItem(ax)
pos = np.mgrid[0:1,0:1,0:1].reshape(3,1,1).transpose(1,2,0)
size = np.empty((1,1,3))
size[...,0:2] = 1
size[...,2] = 5
bg = gl.GLBarGraphItem(pos, size)
##bg.setColor(1., 1., 1., 1.)
w.addItem(bg)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
I tried to use .setColor() method with no success, the object (GlBarGraphItem) itself does not have a method for setting color I believe.
Any hint how to progress?
Upvotes: 0
Views: 1036
Reputation: 243937
If the code of the GLMeshItem
paint()
method is revised:
if self.colors is None:
color = self.opts['color']
if isinstance(color, QtGui.QColor):
glColor4f(*fn.glColor(color))
else:
glColor4f(*color)
so the setColor()
function expects a QColor
or a tuple of 4 elements so you can use the following methods:
bg.setColor((0., 1., 0., 1))
color = QtGui.QColor("pink")
bg.setColor(color)
color = QtGui.QColor(120, 14, 12)
bg.setColor(color)
Upvotes: 1