def addArrow(self, **kwargs): defaults = { "index": 24, "pen": "k", "brush": "k", "headLen":16 } defaults.update(kwargs) arr = pg.CurveArrow(self.ellipseCurve, **defaults) return arr
def liss_animate(self, val): if val and self.liss_ready and self.Liss_show.isChecked(): self.freezeButton.setChecked(True) self.liss_animate_arrow1 = pg.CurveArrow(self.curve_lis) if (self.liss_x == 0): self.liss_animate_arrow2 = pg.CurveArrow(self.curve1) elif (self.liss_x == 1): self.liss_animate_arrow2 = pg.CurveArrow(self.curve2) elif (self.liss_x == 2): self.liss_animate_arrow2 = pg.CurveArrow(self.curve3) elif (self.liss_x == 3): self.liss_animate_arrow2 = pg.CurveArrow(self.curve4) if (self.liss_y == 0): self.liss_animate_arrow3 = pg.CurveArrow(self.curve1) elif (self.liss_y == 1): self.liss_animate_arrow3 = pg.CurveArrow(self.curve2) elif (self.liss_y == 2): self.liss_animate_arrow3 = pg.CurveArrow(self.curve3) elif (self.liss_y == 3): self.liss_animate_arrow3 = pg.CurveArrow(self.curve4) self.plot.addItem(self.liss_animate_arrow1) self.plot.addItem(self.liss_animate_arrow2) self.plot.addItem(self.liss_animate_arrow3) self.liss_anim1 = self.liss_animate_arrow1.makeAnimation(loop=-1) self.liss_anim2 = self.liss_animate_arrow2.makeAnimation(loop=-1) self.liss_anim3 = self.liss_animate_arrow3.makeAnimation(loop=-1) self.liss_anim1.start() self.liss_anim2.start() self.liss_anim3.start() else: self.freezeButton.setChecked(False) try: self.liss_anim1.stop() self.liss_anim2.stop() self.liss_anim3.stop() self.plot.removeItem(self.liss_animate_arrow1) self.plot.removeItem(self.liss_animate_arrow2) self.plot.removeItem(self.liss_animate_arrow3) except: pass
def create_arrow(self, curv, row, col): """"Create all the arrows.""" self.curves.append(pg.PlotCurveItem(x=curv[0], y=curv[1])) self.arrows.append(pg.CurveArrow(self.curves[-1])) val = 50 * self.width / 50000 self.arrows[-1].setStyle(tipAngle=60, tailLen=20 * val, tailWidth=10 * val, headLen=20 * val, pen=None, brush='fc0303') self.vb.addItem(self.arrows[-1]) self.animations.append(self.arrows[-1].makeAnimation(loop=-1)) self.animations[-1].setDuration(1000) if not self.preview: self.animations[-1].start() return len(self.arrows) - 1
def startScroll(self): """ 자동스크롤을 시작한다 """ #스크롤이 Stop상태가 아니면 동작하지 않음 if(self.timer != 0): return #CurveArrow의 위치를 계산 cur_viewrange = self.plotwidget_lst[8 - self.scroll_level].getViewBox().viewRange()[0] cur_region = self.graph.region_lst[8 - self.scroll_level].getRegion() cur_region_mid = (cur_region[0] + cur_region[1]) / 2 cur_index = bisect_left(self.graph.times, cur_region_mid) #CurveArrow를 추가해줌 self.curve_arrow = pg.CurveArrow(self.plotwidget_lst[8 - self.scroll_level].getPlotItem().listDataItems()[0], index=cur_index) self.plotwidget_lst[8 - self.scroll_level].addItem(self.curve_arrow) #타이머 오브젝트 생성 self.timer = QtCore.QTimer() self.timer.timeout.connect(self.scrollEvent) self.scroll_active = True self.timer.start(250)
tailLen=None, brush=None) a4 = pg.ArrowItem(angle=-20, tipAngle=30, baseAngle=-30, headLen=40, tailLen=None) a2.setPos(10, 0) a3.setPos(20, 0) a4.setPos(30, 0) p.addItem(a1) p.addItem(a2) p.addItem(a3) p.addItem(a4) p.setRange(QtCore.QRectF(-20, -10, 60, 20)) ## Animated arrow following curve c = p2.plot(x=np.sin(np.linspace(0, 2 * np.pi, 1000)), y=np.cos(np.linspace(0, 6 * np.pi, 1000))) a = pg.CurveArrow(c) a.setStyle(headLen=40) p2.addItem(a) anim = a.makeAnimation(loop=-1) anim.start() ## Start Qt event loop unless running in interactive mode or using pyside. if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()
def main(): end = 3600*24*365 dt = 3600#0.001 sum_step = int(end // dt + 1) planets = Planet_system() planets.add_planet("Sun", 1.989e30, 0.0, 0.0, 0.0, 0.0) planets.add_planet("Earth", 5.972e24, 1.496e11, 0.0, 0.0, 29.4e3) #planets.add_planet("Earth2", 5.972e24, 1.496e11+4.055e8, 0.0, 0.0, 40.4e3) planets.add_planet("Moon", 7.348e22, 1.496e11+4.055e8, 0.0, 0.0, 29.4e3+1.01e3) #planets.add_planet("planet2", 0.01, 1.2, 0.0, 0.0, 1.2) #planets.add_planet("Earth", 5.972e24,0.0, 0.0, 0.0, 0.0) #planets.add_planet("Moon", 7.348e22, 4.055e8, 0.0, 0.0, 1.01e3) for i in range(sum_step): RK4(planets, dt, i) print(i) app = QtGui.QApplication([]) w = QtGui.QMainWindow() cw = pg.GraphicsLayoutWidget() w.show() w.resize(400,600) w.setCentralWidget(cw) w.setWindowTitle('pyqtgraph example: Arrow') p2 = cw.addPlot(row=1, col=0) z = [0]*8761 #plt.plot(planets[0].x, planets[0].y, z, "rs-") #plt.plot(planets[1].x, planets[1].y, z, "b:") #plt.plot(planets[2].x, planets[2].y, z, "g:") c = [] c.append(p2.plot(x=planets[0].x, y=planets[0].y, color="b"))#z=[0]*8761)) c.append(p2.plot(x=planets[1].x, y=planets[1].y, cloor="r"))#z=[0]*8761)) a = [] a.append(pg.CurveArrow(c[0])) a.append(pg.CurveArrow(c[1])) #a2 = pg.CurveArrow(c2) a[0].setStyle(headLen=40) p2.addItem(a[0]) p2.addItem(a[1]) anim = [] anim.append(a[0].makeAnimation(loop=-1)) anim.append(a[1].makeAnimation(loop=-1)) #anim = a[0].makeAnimation(loop=-1) #anim2 = a[1].makeAnimation(loop=-1) anim[0].start() anim[1].start() """w = gl.GLViewWidget() w.opts['distance'] = 20 w.show() w.setWindowTitle('pyqtgraph example: GLScatterPlotItem') gx = gl.GLGridItem() gx.rotate(90, 0, 1, 0) gx.translate(-10, 0, 0) w.addItem(gx) gy = gl.GLGridItem() gy.rotate(90, 1, 0, 0) gy.translate(0, -10, 0) w.addItem(gy) gz = gl.GLGridItem() gz.translate(0, 0, -10) w.addItem(gz) #n = 51""" """ y = planets[1].y #np.linspace(-10,10,n) x = planets[1].x #np.linspace(-10,10,100) z = [0]*8762 for i in range(len(planets[1].x)): yi = np.array([y[i]]) pts = np.vstack([x[i],yi,z[i]]).transpose() # yi = np.array([y[i]]*100) # d = (x**2 + yi**2)**0.5 # z = 10 * np.cos(d) / (d+1) # pts = np.vstack([x,yi,z]).transpose() plt = gl.GLLinePlotItem(pos=pts, color=pg.glColor(225,225,225), width=10, antialias=True) w.addItem(plt)""" #sp1 = gl.GLScatterPlotItem(pos=[planets[1].x, planets[1].y, [0]*8761], size=[0.5]*8761, color=[[0.0, 1.0, 0.0, 0.5]]*8761, pxMode=False) #sp1.translate(5,5,0) #w.addItem(sp1) sys.exit(app.exec_()) """
def drawBlocSideView(self): # draw root & tip bloc # remove text items with height & margin self.plotBlocSideViewRoot.removeItem(self.hTrailingRootText) self.plotBlocSideViewRoot.removeItem(self.hLeadingRootText) self.plotBlocSideViewTip.removeItem(self.hTrailingTipText) self.plotBlocSideViewTip.removeItem(self.hLeadingTipText) self.plotBlocSideViewRoot.removeItem(self.hMaxRootText) self.plotBlocSideViewRoot.removeItem(self.hMinRootText) self.plotBlocSideViewTip.removeItem(self.hMaxTipText) self.plotBlocSideViewTip.removeItem(self.hMinTipText) self.plotBlocSideViewRoot.removeItem(self.arrowRoot) self.plotBlocSideViewTip.removeItem(self.arrowTip) #draw the bloc blocChordRoot = self.cRoot.value() + self.mLeading.value( ) + self.mTrailingRoot.value() blocChordTip = self.cTip.value() + self.mLeading.value( ) + self.mTrailingTip.value() blocRootX = [0, blocChordRoot, blocChordRoot, 0, 0] blocTipX = [0, blocChordTip, blocChordTip, 0, 0] #hOffset = self.hOffset.value() blocHZ = self.blocHZ.value() blocRootY = [0, 0, blocHZ, blocHZ, 0] blocTipY = blocRootY self.linePlotBlocSideViewRootBloc.setData(blocRootX, blocRootY) self.linePlotBlocSideViewTipBloc.setData(blocTipX, blocTipY) #draw root & tip profiles #then update profil self.linePlotBlocSideViewRootProfile.setData(self.pRootX.tolist(), self.pRootY.tolist()) self.linePlotBlocSideViewTipProfile.setData(self.pTipX.tolist(), self.pTipY.tolist()) if self.cbShowWire.isChecked(): #print("redraw wire") self.linePlotBlocSideViewRootWire.setData(self.oSimRX, self.oSimRY) self.linePlotBlocSideViewTipWire.setData(self.oSimTX, self.oSimTY) if len(self.oSimRX) > 2: self.arrowRoot = pg.CurveArrow(self.linePlotBlocSideViewRootWire) self.arrowRoot.setStyle(headlen=40, pen={'color': 'r'}, brush=None) self.plotBlocSideViewRoot.addItem(self.arrowRoot) self.arrowTip = pg.CurveArrow(self.linePlotBlocSideViewTipWire) self.arrowTip.setStyle(headlen=40, pen={'color': 'b'}, brush=None) self.plotBlocSideViewTip.addItem(self.arrowTip) else: self.linePlotBlocSideViewRootWire.setData([], []) self.linePlotBlocSideViewTipWire.setData([], []) #at the end add text with all heights and margins if (len(self.tRootX) > 0) and (len(self.tTipX) > 0): self.hTrailingRootText = pg.TextItem( text="{:.1f}".format(self.hTrailingRoot), color="r", anchor=(0, 0)) # text for margin trailing Root self.hTrailingRootText.setPos(self.mTrailingRoot.value(), self.hTrailingRoot) self.plotBlocSideViewRoot.addItem(self.hTrailingRootText) self.hLeadingRootText = pg.TextItem(text="{:.1f}".format( self.hLeadingRoot), color="r", anchor=(1, 0)) self.hLeadingRootText.setPos( self.cRoot.value() + self.mTrailingRoot.value(), self.hLeadingRoot) self.plotBlocSideViewRoot.addItem(self.hLeadingRootText) self.hTrailingTipText = pg.TextItem(text="{:.1f}".format( self.hTrailingTip), color="b", anchor=(0, 0)) self.hTrailingTipText.setPos(self.mTrailingTip.value(), self.hTrailingTip) self.plotBlocSideViewTip.addItem(self.hTrailingTipText) self.hLeadingTipText = pg.TextItem(text="{:.1f}".format( self.hLeadingTip), color="b", anchor=(1, 0)) self.hLeadingTipText.setPos( self.cTip.value() + self.mTrailingTip.value(), self.hLeadingTip) self.plotBlocSideViewTip.addItem(self.hLeadingTipText) self.hMaxRootText = pg.TextItem(text="{:.1f}".format(self.hMaxRoot), color="r", anchor=(0.5, 1)) self.hMaxRootText.setPos( self.mTrailingRoot.value() + self.cRoot.value() / 2, self.blocHZ.value() - self.hMaxRoot) self.plotBlocSideViewRoot.addItem(self.hMaxRootText) self.hMinRootText = pg.TextItem(text="{:.1f}".format(self.hMinRoot), color="r", anchor=(0.5, 0)) self.hMinRootText.setPos( self.mTrailingRoot.value() + self.cRoot.value() / 2, self.hMinRoot) self.plotBlocSideViewRoot.addItem(self.hMinRootText) self.hMaxTipText = pg.TextItem(text="{:.1f}".format(self.hMaxTip), color="b", anchor=(0.5, 1)) self.hMaxTipText.setPos( self.mTrailingTip.value() + self.cTip.value() / 2, self.blocHZ.value() - self.hMaxTip) self.plotBlocSideViewTip.addItem(self.hMaxTipText) self.hMinTipText = pg.TextItem(text="{:.1f}".format(self.hMinTip), color="b", anchor=(0.5, 0)) self.hMinTipText.setPos( self.mTrailingTip.value() + self.cTip.value() / 2, self.hMinTip) self.plotBlocSideViewTip.addItem(self.hMinTipText)
def plot_result(self): self.plot_widget.append(Plot()) self.plot3d_widget.append(gl.GLViewWidget())#(GLViewer())#(Plot3D()) if len(self.plot_widget) >= 2: self.plot_widget.pop(0) if len(self.plot3d_widget) >= 2: self.plot3d_widget.pop(0) if self.resultcontainer.results["dim"]:#self.resultcontainer.chk_2dor3d == True: self.plot_widget[-1].show() p = self.plot_widget[-1].plotw.addPlot(row=0, col=0) p.addLegend() p.showGrid(True, True) for i in range(len(self.resultcontainer.results["planets"])): self.plot.append(p.plot(x=self.resultcontainer.results["planets"][i]["x"],\ y=self.resultcontainer.results["planets"][i]["y"],\ pen=(255/len(self.resultcontainer.results["planets"])*(i+1), 255/len(self.resultcontainer.results["planets"])*i, 255/len(self.resultcontainer.results["planets"])*(len(self.resultcontainer.results["planets"])-i-1)),\ name=self.resultcontainer.results["planets"][i]["name"])) self.arrow.append(pg.CurveArrow(self.plot[i])) self.text.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"], anchor=(0.5, -1.0))) #self.arrow.append(pg.ArrowItem()) self.initarrow.append(pg.ArrowItem()) self.inittext.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"]+" Init",anchor=(0.5, -1.0))) self.arrow_here_xy.append(pg.ArrowItem()) #self.text_here_xy.append(pg.TextItem("Here", anchor=(0.5, -1.0))) self.initarrow[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["y"][0]) self.inittext[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["y"][0]) #p.addItem(arrow[i]) self.text[i].setParentItem(self.arrow[i]) self.initarrow[i].setParentItem(self.plot[i]) p.addItem(self.inittext[i]) self.arrow_here_xy[i].setParentItem(self.plot[i]) #p.addItem(initarrow[i]) self.anim.append(self.arrow[i].makeAnimation(loop=-1)) for i in range(len(self.resultcontainer.results["planets"])): self.anim[i].start() else: self.plot_widget[-1].resize(450,900) self.plot_widget[-1].show() p_xy = self.plot_widget[-1].plotw.addPlot(row=0, col=0) p_xz = self.plot_widget[-1].plotw.addPlot(row=1, col=0) p_yz = self.plot_widget[-1].plotw.addPlot(row=2, col=0) p_xy.addLegend() #p_xz.addLegend() #p_yz.addLegend() p_xy.setLabel('left',"Y") p_xy.setLabel('bottom',"X") p_xz.setLabel('left',"Z") p_xz.setLabel('bottom',"X") p_yz.setLabel('left',"Z") p_yz.setLabel('bottom',"Y") p_xy.showGrid(True, True) p_xz.showGrid(True, True) p_yz.showGrid(True, True) for i in range(len(self.resultcontainer.results["planets"])): self.plot_xy.append(p_xy.plot(self.resultcontainer.results["planets"][i]["x"],\ self.resultcontainer.results["planets"][i]["y"],\ pen=(255/len(self.resultcontainer.results["planets"])*(i+1), 255/len(self.resultcontainer.results["planets"])*i, 255/len(self.resultcontainer.results["planets"])*(len(self.resultcontainer.results["planets"])-i-1)),\ name=self.resultcontainer.results["planets"][i]["name"])) self.plot_xz.append(p_xz.plot(self.resultcontainer.results["planets"][i]["x"],\ self.resultcontainer.results["planets"][i]["z"],\ pen=(255/len(self.resultcontainer.results["planets"])*(i+1), 255/len(self.resultcontainer.results["planets"])*i, 255/len(self.resultcontainer.results["planets"])*(len(self.resultcontainer.results["planets"])-i-1)),\ name=self.resultcontainer.results["planets"][i]["name"])) self.plot_yz.append(p_yz.plot(self.resultcontainer.results["planets"][i]["y"],\ self.resultcontainer.results["planets"][i]["z"],\ pen=(255/len(self.resultcontainer.results["planets"])*(i+1), 255/len(self.resultcontainer.results["planets"])*i, 255/len(self.resultcontainer.results["planets"])*(len(self.resultcontainer.results["planets"])-i-1)),\ name=self.resultcontainer.results["planets"][i]["name"])) self.arrow_xy.append(pg.CurveArrow(self.plot_xy[i])) self.arrow_xz.append(pg.CurveArrow(self.plot_xz[i])) self.arrow_yz.append(pg.CurveArrow(self.plot_yz[i])) self.text_xy.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"], anchor=(0.5, -1.0))) self.text_xz.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"], anchor=(0.5, -1.0))) self.text_yz.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"], anchor=(0.5, -1.0))) self.initarrow_xy.append(pg.ArrowItem()) self.initarrow_xz.append(pg.ArrowItem()) self.initarrow_yz.append(pg.ArrowItem()) self.inittext_xy.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"]+" Init",anchor=(0.5, -1.0))) self.inittext_xz.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"]+" Init",anchor=(0.5, -1.0))) self.inittext_yz.append(pg.TextItem(self.resultcontainer.results["planets"][i]["name"]+" Init",anchor=(0.5, -1.0))) self.arrow_here_xy.append(pg.ArrowItem()) self.arrow_here_xz.append(pg.ArrowItem()) self.arrow_here_yz.append(pg.ArrowItem()) #self.text_here_xy.append(pg.TextItem("Here", anchor=(0.5, -1.0))) #self.text_here_xz.append(pg.TextItem("Here", anchor=(0.5, -1.0))) #self.text_here_yz.append(pg.TextItem("Here", anchor=(0.5, -1.0))) self.initarrow_xy[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["y"][0]) self.initarrow_xz[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["z"][0]) self.initarrow_yz[i].setPos(self.resultcontainer.results["planets"][i]["y"][0],\ self.resultcontainer.results["planets"][i]["z"][0]) self.inittext_xy[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["y"][0]) self.inittext_xz[i].setPos(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["z"][0]) self.inittext_yz[i].setPos(self.resultcontainer.results["planets"][i]["y"][0],\ self.resultcontainer.results["planets"][i]["z"][0]) self.text_xy[i].setParentItem(self.arrow_xy[i]) self.text_xz[i].setParentItem(self.arrow_xz[i]) self.text_yz[i].setParentItem(self.arrow_yz[i]) self.initarrow_xy[i].setParentItem(self.plot_xy[i]) self.initarrow_xz[i].setParentItem(self.plot_xz[i]) self.initarrow_yz[i].setParentItem(self.plot_yz[i]) p_xy.addItem(self.inittext_xy[i]) p_xz.addItem(self.inittext_xz[i]) p_yz.addItem(self.inittext_yz[i]) self.arrow_here_xy[i].setParentItem(self.plot_xy[i]) self.arrow_here_xz[i].setParentItem(self.plot_xz[i]) self.arrow_here_yz[i].setParentItem(self.plot_yz[i]) self.anim_xy.append(self.arrow_xy[i].makeAnimation(loop=-1)) self.anim_xz.append(self.arrow_xz[i].makeAnimation(loop=-1)) self.anim_yz.append(self.arrow_yz[i].makeAnimation(loop=-1)) for i in range(len(self.resultcontainer.results["planets"])): self.anim_xy[i].start() self.anim_xz[i].start() self.anim_yz[i].start() self.plot3d_widget[-1].show() #self.plot3d_widget[-1].opts['distance'] = 2000 gx = gl.GLGridItem() gx.rotate(90, 0, 1, 0) #gx.scale(10,10,10) #gx.translate(-10, 0, 0) self.plot3d_widget[-1].addItem(gx)#.glplotw.addItem(gx) ax = gl.GLAxisItem(antialias=True) self.plot3d_widget[-1].addItem(ax) gy = gl.GLGridItem() gy.rotate(90, 1, 0, 0) #gy.translate(0, -10, 0) self.plot3d_widget[-1].addItem(gy)#.glplotw.addItem(gy) gz = gl.GLGridItem() #gz.translate(0, 0, -10) self.plot3d_widget[-1].addItem(gz)#.glplotw.addItem(gz) for i in range(len(self.resultcontainer.results["planets"])): self.pos.append([]) x = np.array(self.resultcontainer.results["planets"][i]["x"]) y = np.array(self.resultcontainer.results["planets"][i]["y"]) z = np.array(self.resultcontainer.results["planets"][i]["z"]) """self.pos[i] = np.vstack([self.resultcontainer.results["planets"][i]["x"], self.resultcontainer.results["planets"][i]["y"], self.resultcontainer.results["planets"][i]["z"]]).transpose() """ self.pos[i] = np.vstack([x,y,z]).transpose() self.plot_3d.append(gl.GLLinePlotItem(pos=self.pos[i],\ color=pg.glColor(255/len(self.resultcontainer.results["planets"])*(i+1), 255/len(self.resultcontainer.results["planets"])*i, 255/len(self.resultcontainer.results["planets"])*(len(self.resultcontainer.results["planets"])-i-1)),\ width=1.0,\ antialias=True)) self.plot3d_widget[-1].addItem(self.plot_3d[i])#.glplotw.addItem(self.plot_3d[i]) self.plot3d_widget[-1].qglColor(Qt.white) self.plot3d_widget[-1].renderText(self.resultcontainer.results["planets"][i]["x"][0],\ self.resultcontainer.results["planets"][i]["y"][0],\ self.resultcontainer.results["planets"][i]["z"][0],\ self.resultcontainer.results["planets"][i]["name"]) """for k in range(len(self.resultcontainer.results["planets"][i]["x"])): self.pos[i].append([self.resultcontainer.results["planets"][i]["x"][k], self.resultcontainer.results["planets"][i]["y"][k], self.resultcontainer.results["planets"][i]["z"][k]]) self.plot_3d.append(gl.GLLinePlotItem(pos=self.pos[i], antialias=True)) self.plot3d_widget[-1].glplotw.addItem(self.plot_3d[i])""" """for k in range(len(self.resultcontainer.results["planets"][i]["x"])):