pyqtgraph:保存/导出3D图形

我已经用pyqtgraph绘制了3D图形,我想保存/导出它.
在3D图上单击鼠标右键不会打开任何允许我保存图的上下文菜单.
http://www.pyqtgraph.org/documentation/exporting.html处的文档告诉我如何从程序中进行保存/导出,但是按照3D的说明进行操作会导致黑色保存的图像.

这是我的代码的相关部分:

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

app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setCameraPosition(distance=50)

g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10) 
w.addItem(g)

z=np.genfromtxt('../mydata.txt') 
p1 = gl.GLSurfacePlotItem(z=z, shader='shaded', color=(0.5, 0.5, 1, 1))

p1.scale(0.1, 0.1, 0.1)
p1.translate(-0, 0, 0)
w.addItem(p1)

w.grabFrameBuffer().save('test.png')

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

mydata.txt包含一个2D浮点值数组.该图正确显示在我的屏幕上.
有没有人成功地从pyqtgraph程序保存/导出3D图,或者能够在上面的代码中发现问题? (Linux,anaconda3中使用Qt版本4.8.7).

解决方法:

这是帮助我解决问题的相关信息:
https://groups.google.com/forum/#!msg/pyqtgraph/dKT1Z3nIeow/OErAgRPAbB8J

那是:

d = w.renderToArray((1000, 1000))
pg.makeQImage(d).save(filename)

以下是创建3D图并保存的完整代码:

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

app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setCameraPosition(distance=50)

g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10) 
w.addItem(g)

z=np.genfromtxt('../../TestData/textAsImage.txt') 
p1 = gl.GLSurfacePlotItem(z=z, shader='shaded', color=(0.5, 0.5, 1, 1))

p1.scale(0.1, 0.1, 0.1)
p1.translate(-0, 0, 0)
w.addItem(p1)

filename = 'yourfilename.png'
d = w.renderToArray((1000, 1000))
pg.makeQImage(d).save(filename)

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
上一篇:python-元素的numpy条件格式


下一篇:python – 具有多个断点的PyQt可拖动线