Jan-19-2020, 04:20 PM
Hi, I am trying to plot two graphs in one window, one 2d and another 3d. I am able to get the 2d plot to work but when I try to plot in 3d using GLSurfacePlotItem I get the following error:
this is the code I am using(.py)
Error:AttributeError: 'GLViewWidget' object has no attribute 'GLSurfacePlotItem'
the 3d plot widget was promoted with class name:GLViewWidget, headerfile: pyqtgraph.opengl.h. how can I plot in 3d using pyqtgraph? I have the code that I want to run working, but it isn't inserted in a pyqt5 window. this is the code I am using(.py)
from PyQt5 import QtWidgets, uic #import pyqtgraph.opengl as gl import sys import numpy as np class MainWindow(QtWidgets.QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) #Load the UI Page uic.loadUi('help.ui', self) # Set up plots axes self.graphWidget_2D.setLabel('left', 'Pixels') self.graphWidget_2D.setLabel('bottom', 'Time', 'days') self.plot() def plot(self): Z = np.ones((10, 10)) self.graphWidget_3D.GLSurfacePlotItem(z=Z, shader='shaded', color=(0.5, 0.5, 1, 1)) a = np.random.randn(150) b = np.random.randn(150) self.graphWidget_2D.plot(np.sort(a), np.sort(b)) def main(): app = QtWidgets.QApplication(sys.argv) main = MainWindow() main.show() sys.exit(app.exec_()) if __name__ == '__main__': main()and this is the ui file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1120</width> <height>833</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> <widget class="PlotWidget" name="graphWidget_2D" native="true"/> </item> <item row="0" column="1"> <widget class="GLViewWidget" name="graphWidget_3D" native="true"/> </item> <item row="1" column="0"> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> <item row="1" column="1"> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1120</width> <height>26</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionb"/> <addaction name="actiona"/> <addaction name="actionSave"/> <addaction name="separator"/> <addaction name="actionOptions"/> <addaction name="separator"/> <addaction name="actionExit"/> </widget> <addaction name="menuFile"/> </widget> <widget class="QStatusBar" name="statusbar"/> <action name="actiona"> <property name="text"> <string>Open</string> </property> </action> <action name="actionb"> <property name="text"> <string>File</string> </property> </action> <action name="actionOptions"> <property name="text"> <string>Options</string> </property> </action> <action name="actionSave"> <property name="text"> <string>Save</string> </property> </action> <action name="actionExit"> <property name="text"> <string>Exit</string> </property> </action> </widget> <customwidgets> <customwidget> <class>PlotWidget</class> <extends>QWidget</extends> <header>pyqtgraph.h</header> <container>1</container> </customwidget> <customwidget> <class>GLViewWidget</class> <extends>QWidget</extends> <header>pyqtgraph.opengl.h</header> <container>1</container> </customwidget> </customwidgets> <resources/> <connections/> </ui>