fromPyQt5importQtCore,QtWidgets,QtWebEngineWidgetsimportplotly.expressaspxclassWidget(QtWidgets.QWidget):def__init__(self,parent=None):super().__init__(parent)self.button=QtWidgets.QPushButton('Plot',self)self.browser=QtWebEngineWidgets.QWebEngineView(self)vlayout=QtWidgets.QVBoxLayout(self)vlayout.addWidget(self.button,alignment=QtCore.Qt.AlignHCenter)vlayout.addWidget(self.browser)self.button.clicked.connect(self.show_graph)self.resize(1000,800)defshow_graph(self):df=px.data.tips()fig=px.box(df,x="day",y="total_bill",color="smoker")fig.update_traces(quartilemethod="exclusive")# or "inclusive", or "linear" by defaultself.browser.setHtml(fig.to_html(include_plotlyjs='cdn'))if__name__=="__main__":app=QtWidgets.QApplication([])widget=Widget()widget.show()app.exec()
model=TableModel(appData)curTable.setModel(model)# set columns resize modelcurTable.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)curTable.horizontalHeader().setSectionResizeMode(0,QtWidgets.QHeaderView.Interactive)curTable.setColumnWidth(0,self.parent_widget.width()//2)curTable.horizontalHeader().setSectionResizeMode(1,QtWidgets.QHeaderView.ResizeToContents)curTable.horizontalHeader().setSectionResizeMode(3,QtWidgets.QHeaderView.ResizeToContents)curTable.horizontalHeader().setSectionResizeMode(4,QtWidgets.QHeaderView.ResizeToContents)
fromPyQt5.QtCoreimportQtfromPyQt5importQtCoreclassTableModel(QtCore.QAbstractTableModel):def__init__(self,data):super(TableModel,self).__init__()self._data=datadefdata(self,index,role):ifrole==Qt.DisplayRole:value=self._data.iloc[index.row(),index.column()]returnstr(value)defrowCount(self,index):returnself._data.shape[0]defcolumnCount(self,index):returnself._data.shape[1]defheaderData(self,section,orientation,role):# section is the index of the column/row.ifrole==Qt.DisplayRole:iforientation==Qt.Horizontal:returnstr(self._data.columns[section])iforientation==Qt.Vertical:returnstr(self._data.index[section])