def initRenderPlot(self, iSlice, vname): logger.debug('GlPlot::initRenderPlot()') #self.glWin = x = np.linspace(-12, 12, 50) y = np.linspace(-12, 12, 50) colors = np.ones((50, 50, 4), dtype=float) colors[..., 0] = np.clip( np.cos(((x.reshape(50, 1)**2) + (y.reshape(1, 50)**2))**0.5), 0, 1) colors[..., 1] = colors[..., 0] if vname == 'Anterior': self.glWin[vname] = gl.GLSurfacePlotItem(z=iSlice, computedNormals=False, smooth=False, shader='shaded', color=(0.8, 0.8, 1, 1)) self.glWin[vname].translate(-40, 0, -20) if vname == 'Lateral': self.glWin[vname] = gl.GLSurfacePlotItem(z=iSlice, computedNormals=False, smooth=False, shader='shaded', color=(0.6, 0.5, 1, 1)) self.glWin[vname].translate(-40, 0, -20) self.glWin[vname].scale(0.5, 0.5, self.zScale) self.win.addItem(self.glWin[vname]) self.glWin[vname].rotate(110, 0, 0, 1) self.isRendered = True
def plot_3d(self, conf_levels=None): app = QtGui.QApplication([]) w = gl.GLViewWidget() w.show() w.setWindowTitle('2d distribution plot') w.setCameraPosition(distance=50) g = gl.GLGridItem() g.scale(1, 1, 1) g.setDepthValue( 10) # draw grid after surfaces since they may be translucent w.addItem(g) if 1: x, y = np.linspace(self.x[0], self.x[-1], 300), np.linspace(self.y[0], self.y[-1], 300) p1 = gl.GLSurfacePlotItem(x=x, y=y, z=self.inter(x, y), shader='normalColor') else: p1 = gl.GLSurfacePlotItem(x=self.x, y=self.y, z=self.z, shader='normalColor') x_s, y_s = 20 / (self.x[-1] - self.x[0]), 20 / (self.y[-1] - self.y[0]) x_t, y_t = -(self.x[-1] + self.x[0]) / 2 * x_s, -(self.y[-1] + self.y[0]) / 2 * y_s p1.scale(x_s, y_s, 10 / np.max(self.z.flatten())) p1.translate(x_t, y_t, 0) w.addItem(p1) if conf_levels is not None: fig, ax = plt.subplots() if isinstance(conf_levels, float): conf_levels = [conf_levels] for c in conf_levels: print(c) cs = ax.contour(self.X, self.Y, self.z, levels=[c], origin='lower') p = cs.collections[0].get_paths() for l in p: x, y = l.vertices.transpose()[0], l.vertices.transpose()[1] z = np.ones_like(x) * c line = gl.GLLinePlotItem(pos=np.vstack([y, x, z]).transpose(), antialias=True) line.scale(y_s, x_s, 10 / np.max(self.z.flatten())) line.translate(y_t, x_t, 0) w.addItem(line) app.instance().exec_()
def __init__(self, timeres=100, cols=90, rows=100): self.timeRes = timeres ## Animated example ## compute surface vertex data self.cols = cols self.rows = rows self.x = np.linspace(-8, 8, self.cols + 1) self.y = np.linspace(-8, 8, self.rows + 1) xx, yy = np.meshgrid(self.y, self.x) self.z = np.sin(xx**2 + yy**2) * 20 / (xx**2 + yy**2 + 0.1 ) # - abs(xx) -abs(yy) # self.z = 8-abs(xx+yy)-abs(yy-xx) self.pTime = [] for i in range(self.timeRes): self.pTime.append(self.z * i / self.timeRes) ## create a surface plot, tell it to use the 'heightColor' shader ## since this does not require normal vectors to render (thus we ## can set computeNormals=False to save time when the mesh updates) self.p = gl.GLSurfacePlotItem(x=self.x, y=self.y, shader='heightColor', computeNormals=False, smooth=False) self.p.shader()['colorMap'] = np.array( [0.2, 3, 0.5, 0.2, 1, 1, 0.2, 0, 2])
def show_tri_qtgraph(M, T, v): x, y, z = get_xyz(M, T, v) ## Create a GL View widget to display data app = QtGui.QApplication([]) w = gl.GLViewWidget() w.show() w.setCameraPosition(distance=50) ## Add a grid to the view g = gl.GLGridItem() g.scale(2, 2, 1) # draw grid after surfaces since they may be translucent g.setDepthValue(10) w.addItem(g) ## Saddle example with x and y specified print x.shape print y.shape print z.shape x = np.linspace(-8, 8, 50) y = np.linspace(-8, 8, 50) z = 0.1 * ((x.reshape(50, 1)**2) - (y.reshape(1, 50)**2)) print x.shape print y.shape print z.shape #p2 = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader='normalColor') p2 = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader='shaded') #p2.translate(-10,-10,0) w.addItem(p2) app.exec_()
def __init__(self, parent=None, data_2d=None, BINS=None): super(surface3d, self).__init__(parent) self.setupUi(self) global GL_ENABLED self.GL_ENABLED = GL_ENABLED self.BINS = BINS self.plotView.setCameraPosition(distance=50) self.plot = gl.GLSurfacePlotItem(z=data_2d, shader='shaded', color=(0.5, 0.5, 1, 1)) self.data_2d = data_2d self.plot.opts['color'] = (.3, .1, .3, 0.6) self.plot.setShader('balloon') self.plot.setGLOptions('additive') self.plot.opts['computeNormals'] = True #self.plot.scale(BINS/49., BINS/49., .1) self.plot.translate(-1 * BINS / 2, -1 * BINS / 2, 0) self.plotView.addItem(self.plot) self.lastZStep = 0 #self.plotView.setBackgroundColor('w') self.imageView.setImage(data_2d) self.imageView.setPredefinedGradient('thermal') self.imageView.roi.sigRegionChanged.connect(self.roiChanged) self.imageView.ui.roiBtn.clicked.connect( functools.partial(self.imageView.ui.roiPlot.setVisible, False))
def __init__(self, model_wrapper, parent=None): """ The Plot3DWidget is responsible for rendering the 3D chromatogram data, and showing highlights of integration areas :param model_wrapper: the wrapper of the model. :param parent: the parent of this Widget. """ super().__init__(parent=parent) self.listener = Plot3DListener(self, model_wrapper) """The listener for the 3D plot""" self.integrations = {} """The integrations array""" self.surface = gl.GLSurfacePlotItem(computeNormals=False) """The surface to render the chromatogram""" # add the surface to the plot self.addItem(self.surface) # move the camera back a bit self.setCameraPosition(distance=400) # Scale down the height of the mesh. self.surface.scale( 1, 1, 0.00001) # TODO This will need to be done dynamically later. # TODO What is this? -> To get the indices working, the plot is translated depending on how large the data is, # to get the integration highlights to know where to be, this needs to be recorded # because the plot is called within self.notify() they are set in there, that they are here is mostly for clarity self.translation_x, self.translation_y = 0, 0 # Register this widget as an observer of the model_wrapper. model_wrapper.add_observer(self, self.notify) # call notify to draw the model. NOTE: again, if statement not required as notify already checks if model is None. self.notify('model', model_wrapper.model)
def mkPlns(plnOr, org=[0, 0, 0], bxSdLen=1, scl=1, res=100, transp=0.5): edge = True smooth = True shader = 'shaded' glOpt = 'translucent' plnClr = [1, 0, 1, transp] # plnVert=np.array([list(itTl.product([0,1],repeat=3))])[0] if np.array_equal(plnOr, np.array([1, 1, 1])): plnVert = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # plnFc= elif np.array_equal(plnOr, np.array([1, 1, 0])): plnVert = np.array([[1, 0, 0], [1, 1, 0], [0, 1, 1], [0, 0, 1]]) elif np.array_equal(plnOr, np.array([1, 0, 0])): plnVert = np.array([[1, 0, 0], [1, 1, 1], [1, 1, 0], [1, 0, 1]]) plnFc = spatial.Delaunay(plnVert) plnDat = gl.MeshData(vertexes=plnVert, faces=plnFc.convex_hull) plnObj = gl.GLSurfacePlotItem(plnVert, drawEdges=edge, smooth=smooth, color=(plnClr[0], plnClr[1], plnClr[2], plnClr[3]), shader=shader, glOptions=glOpt) plnObj.translate(org[0] + bxSdLen / 2, org[0] + bxSdLen / 2, org[0] + bxSdLen / 2) return plnObj
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.create_surface() self.gr = gl.GLViewWidget() self.p4 = gl.GLSurfacePlotItem(x=self.x[:, 0], y=self.y[0, :], shader='normalColor', smooth=False) self.gr.addItem(self.p4) md = gl.MeshData.sphere(rows=10, cols=20) self.sphere = gl.GLMeshItem(meshdata=md, shader="normalColor") self.gr.addItem(self.sphere) layout = QVBoxLayout() layout.addWidget(self.gr) self.ui.graph_widget.setLayout(layout) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update) self.index = 0
def pgPlotSurface(x, y, z, shader='normalColor', autoscale=True, title=None): ''' Adds a new window with a surface plot and a grid item. Returns w = view widget item g = grid item p = plot item ''' # win = pg.GraphicsWindow() w = gl.GLViewWidget() w.show() w.setWindowTitle(title) g = gl.GLGridItem() if autoscale == True: sx = np.max(np.abs(x)) sy = np.max(np.abs(y)) g.scale(sx, sy, 1) w.setCameraPosition(distance=np.max([sx, sy]) * 2) g.setDepthValue( 10) # draw grid after surfaces since they may be translucent w.addItem(g) p = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader=shader) w.addItem(p) return w, g, p
def __init__(self, pos=None, color=(100, 100, 200), data_shape=1000, widget=None): if not widget: self.app = QtGui.QApplication([]) self.widget = gl.GLViewWidget() self.widget.opts['distance'] = 40 self.widget.show() else: self.widget = widget self.axis = gl.GLAxisItem() self.widget.addItem(self.axis) self.box_item_list = [] if pos is None: x = (np.random.rand((data_shape)) - 0.5) * 20 y = (np.random.rand((data_shape)) - 0.5) * 20 z = (np.random.rand((data_shape)) - 0.5) * 20 pos = np.vstack([x, y, z]).transpose() self.add_new_box(pos) surface_plot = gl.GLSurfacePlotItem() colors = np.array((((0.5, 0.5, 0.5, 0.25), (0.5, 0.5, 1, 0.25)), ((1, 0.5, 0.5, 0.25), (0.5, 1, 0.5, 0.25)))) surface_plot.setData(x=np.array((-10, 10)), y=np.array((-10, 10)), z=np.array(((0, 0), (0, 0))), colors=colors) self.widget.addItem(surface_plot)
def showHeightMap(self, object, visual_divider=4): if self.gm != None: self.w.removeItem(self.gm) self.visual_divider = visual_divider self.object = object x_display_size = len(object.xrange) / self.visual_divider y_display_size = len(object.yrange) / self.visual_divider xdata = array([ object.xrange[x * len(object.xrange) / x_display_size] for x in range(0, x_display_size) ]) ydata = array([ object.yrange[y * len(object.yrange) / y_display_size] for y in range(0, y_display_size) ]) zdata = array([[ object.map[x * len(object.xrange) / len(xdata)][y * len(object.yrange) / len(ydata)] for y in range(0, y_display_size) ] for x in range(0, x_display_size)]) self.gm = gl.GLSurfacePlotItem(x=xdata, y=ydata, z=zdata, color=(0.2, 0.0, 0.0, 0.5), shader='edgeHilight', smooth=False, computeNormals=True) self.w.addItem(self.gm)
def __init__(self, solver, title='Function Viewer'): ''' Initializes the viewer (sets up Qt, creates pyqtgraph plot). Does not actually open the viewer window until start() is called. Arguments: solver -- solver to extract data from title -- title of the graph window ''' # Create GL view widget self.app = QtGui.QApplication([]) self.view = gl.GLViewWidget() self.view.show() self.view.setBackgroundColor(255, 255, 255) self.view.setWindowTitle(title) self.view.setCameraPosition(distance=max(*solver.Z.shape)) # Add function plot self.solver = solver self.plot = gl.GLSurfacePlotItem( x=solver.X, y=solver.Y, z=solver.Z, computeNormals=False, smooth=False, drawEdges=True, drawFaces=False, antialias=True, ) self.view.addItem(self.plot) # Keep track of current frame self.frame = 0
def addSurfaceGraph(self): self.x = np.linspace(-self.widthOfData / 2, self.widthOfData / 2, self.widthOfData) self.y = np.linspace(-self.numberOfData / 2, self.numberOfData / 2, self.numberOfData) self.surfacePlot = gl.GLSurfacePlotItem( self.x, self.y, shader='heightColor', computeNormals=False, smooth=False) # smooth true = faster; dont turn on computenormals self.surfacePlot.shader()['colorMap'] = np.array( [0.01, 0, 0.5, 0.01, 0, 1, 0.01, 0, 2]) # lut self.surfaceData = np.zeros((self.widthOfData, self.numberOfData), dtype=int) ## create a surface plot, tell it to use the 'heightColor' shader ## since this does not require normal vectors to render (thus we ## can set computeNormals=False to save time when the mesh updates) # p4.translate(100, 100, 0) self.addItem(self.surfacePlot) ## Add a grid to the view self.g = gl.GLGridItem() self.g.setSize(x=self.widthOfData * 2, y=self.numberOfData * 2) # g.scale(2,2,1000) self.g.setDepthValue( 10) # draw grid after surfaces since they may be translucent self.addItem(self.g)
def Plot3D(self, data, axisX=None, axisY=None, symbol=True, pen=True, label=None): self.data = data self.dimx = np.shape(self.data)[0] self.dimy = np.shape(self.data)[1] self.pen = pen self.axisX = axisX self.axisY = axisY if self.axisX == None or self.axisY == None: x = np.linspace(-12, 12, self.dimx) y = np.linspace(-12, 12, self.dimy) z = self.data #[:self.dimx,:self.dimy] cm = pg.ColorMap([0, 0.5, 1], [(1., 0., 0., 1.), (0., 0., 1., 1.), (0., 1., 0., 1.)]) colors = cm.map((z + z.min()) / (z.max() - z.min()), mode='float') p1 = gl.GLSurfacePlotItem( z=z, colors=colors, shader='heightColor') #.reshape(50*50,4)) #p1.shader()['colorMap'] = np.array([0.7, 2, 0.5, 0.2, 0.7, 0.7, 0.2, 0, 2]) self.w.addItem(p1) else: print('')
def gauss2d(params_data): mu_x = params_data[0] mu_y = params_data[2] sigma_x = params_data[1] sigma_y = params_data[3] rho = params_data[4] amp = 20 # Should come from fitting offset = 0 # background x = np.arange(-20, 20, 0.5) y = np.arange(-20, 20, 0.5) cross_x = [] cross_y = [] g = np.zeros([len(x), len(x)]) for i in range(len(x)): for j in range(len(y)): a = ((x[i] - mu_x) / sigma_x)**2 b = ((y[j] - mu_y) / sigma_x)**2 c = 2 * rho * (x[i] - mu_x) * (y[j] - mu_y) / sigma_x / sigma_y g[i][j] = offset + amp * np.exp((a + b - c) / (rho**2 - 1) / 2) if g[i][j] > amp / 4: #-5 and g[i][j]<amp/2+5: cross_x.append(x[i]) cross_y.append(y[j]) print(len(cross_x)) plt_gauss_3d = gl.GLSurfacePlotItem(x=x, y=y, z=g, shader='shaded', color=(0.5, 0, 0, 0.5)) # plt_3d = gl.GLSurfacePlotItem(x=data_x,y=data_y,z=peak_counts,shader='normalColor') plt_gauss_3d.translate(-10, 10, 0) win_2.addItem(plt_gauss_3d)
def new3dSurface(self,plot,**args): import scipy.ndimage as ndi surface3d = gl.GLSurfacePlotItem(z=np.array([[0.1,0.1],[0.1,0.1]]), **args) #surface3d.shader()['colorMap']=pg.ColorMap(np.array([0.2,0.4,0.6]),np.array([[255,0,0,255],[0,255,0,255],[0,255,255,255]])).getLookupTable() #surface3d.shader()['colorMap'] = np.array([0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2]) plot.addItem(surface3d) return surface3d
def __init__(self, map, max_time): """ Initialize the graphics window and mesh """ self.map = map self.paths = {} self.max_time = max_time self.t = 0 self.agents = {} self.timer = QtCore.QTimer() # setup the view window self.app = QtGui.QApplication(sys.argv) self.w = gl.GLViewWidget() self.w.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.w.setGeometry(0, 0, 1920, 1080) self.w.show() self.w.setWindowTitle('Multi Agent Path Finding') self.w.setCameraPosition(distance=50, elevation=50, azimuth=225) # Set up 3d surface plot x = np.arange(0, map.cols) - map.cols // 2 y = np.arange(0, map.rows) - map.rows // 2 cmap = plt.cm.get_cmap('jet') minZ = np.min(map.grid) maxZ = np.max(map.grid) rgba_img = cmap((map.grid - minZ) / (maxZ - minZ)) # Create and display surface plot self.surface = gl.GLSurfacePlotItem(x=y, y=x, z=map.grid, colors=rgba_img) self.w.addItem(self.surface)
def initUI(self): #self.statusbar = self.statusBar() #self.statusbar.showMessage('Ready') #lbl1 = QLabel('IFM O3D201 Interface', self) #lbl1.move(15, 10) #self.setGeometry(300, 300, 250, 150) #self.setWindowTitle('Absolute') # opengl defs here # gui part starting here ## Create a GL View widget to display data self.w = gl.GLViewWidget() self.w.show() self.w.setWindowTitle('pyqtgraph example: GLSurfacePlot') self.w.setCameraPosition(distance=200) ## Add a grid to the view self.g = gl.GLGridItem() # grid scale self.g.scale(10, 10, 10) self.g.setDepthValue( 10) # draw grid after surfaces since they may be translucent #self.g.size(700,400 ) self.w.addItem(self.g) self.y = np.arange(50) self.x = np.arange(64) self.p4 = gl.GLSurfacePlotItem(x=self.x, y=self.y, shader='heightColor', computeNormals=False, smooth=False) # p4 = gl.GLSurfacePlotItem(x=x[:,0], y = y[0,:], shader='heightColor', computeNormals=False, smooth=False) # whats this? # p4.shader()['colorMap'] = np.array([0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2]) self.p4.shader()['colorMap'] = np.array( [0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2]) # translate coordinates starting point (x,y,z) # optimum (-5,-5,0) self.p4.translate(-5, -5, 0) self.w.addItem(self.p4) # old show here self.show() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update) self.timer.start(1000)
def __init__(self, parent=None): super(GraphWindow, self).__init__(parent) # カメラデバイスをオープン self.cap = cv2.VideoCapture(0) # self.cap = cv2.VideoCapture(STREAM_URL) _, frame = self.cap.read() # frame[y, x]であることに注意 self.width = frame.shape[1] self.height = frame.shape[0] # 3次元プロットのためのウィジェット self.w = gl.GLViewWidget() self.w.setWindowTitle('3D animation plot') # ウィンドウ出現場所、ウィンドウサイズ self.w.setGeometry(110, 110, 1200, 800) # 3次元プロットを観測するカメラの場所 self.w.setCameraPosition( distance=np.sqrt(self.width**2 + self.height) * 1.5) self.w.show() # x平面 gx = gl.GLGridItem() # 回転 gx.rotate(90, 0, 1, 0) # 移動 gx.translate(-self.height / 2, 0, 0) # スケール gx.scale(self.height / 20, self.width / 20, 1) self.w.addItem(gx) # y平面 gy = gl.GLGridItem() gy.rotate(90, 1, 0, 0) gy.translate(0, -self.width / 2, 0) gy.scale(self.height / 20, self.height / 20, 1) self.w.addItem(gy) # z平面 gz = gl.GLGridItem() gz.translate(0, 0, -self.height / 2) gz.scale(self.height / 20, self.width / 20, 1) self.w.addItem(gz) # 画素値をいくつ読みとばすか(大きいほど処理が軽いが、精度に欠ける) self.step = 8 self.x = np.arange(0, self.width, 1) self.y = np.arange(0, self.height, 1) # データの用意 self.p = gl.GLSurfacePlotItem(x=self.y[0:self.height:self.step], y=self.x[0:self.width:self.step], z=np.zeros( (int(self.height / self.step), int(self.width / self.step))), shader='normalColor') self.p.translate(-self.height / 2, -self.width / 2, 0) # データのフレームを設定 self.w.addItem(self.p) # タイマーの用意 self.timer = QtCore.QTimer()
def init_surface(self): """""" surface = gl.GLSurfacePlotItem(shader='heightColor', computeNormals=False, smooth=False) surface.translate(0, -self.gv.DEQUE_LEN / 15, 0) surface.shader()['colorMap'] = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1]) return surface
def add_sea(self): self.removeItem(self.grid) z = pg.gaussianFilter(np.random.normal(size=(100, 100)), (1, 1)) self.sea = gl.GLSurfacePlotItem(z=z, shader='shaded', color=(0.5, 0.5, 1, 1), smooth=True) self.sea.translate(-50, -50, -1) self.addItem(self.sea)
def get_faces(cube, face, x, y, z): return gl.GLSurfacePlotItem(x=x, y=y, z=z, color=cube.colors[face], edgeColor=cube.edgeColor, drawEdges=cube.drawEdges, shader=cube.shader, glOptions=cube.glOptions)
def surface(self, name, x, y, z, colors, alphas=1.0): colors = _extend_color_if_necessary(colors, list(z.shape), alphas) if name not in self._named_items: w_gl_item = gl.GLSurfacePlotItem( x=x, y=y, z=z, shader=None, colors=colors, glOptions='translucent') self._named_items[name] = w_gl_item self.addItem(w_gl_item) else: self._named_items[name].setData( x=x, y=y, z=z, colors=colors)
def update_plot(self, data, attrs=None): if attrs is None: attrs = {} x0 = attrs.get("x0", 0) y0 = attrs.get("y0", 0) xscale = attrs.get("xscale", 1) yscale = attrs.get("yscale", 1) xlabel = attrs.get("xlabel", "X") ylabel = attrs.get("ylabel", "Y") zlabel = attrs.get("zlabel", "Z") plot_args = attrs.get("plot_args", {}) self.cur_data = data self.cur_attrs = attrs if data is None: self.clear_plot() return if self.update_toggle.isChecked(): self.line_scrubber.setMaximum(len(data) - 1) self.img_view.setLabels(xlabel, ylabel, zlabel) if self.most_recent_check.isChecked(): self.line_scrubber.setValue(len(data) - 1) # This updates the line plot # Well, this is a hack. I'm not sure why autorange is disabled after setImage autorange = self.img_view.getView().vb.autoRangeEnabled()[0] autolevels = self.autolevels_check.isChecked() self.img_view.setImage(data, autoRange=autorange, autoLevels=autolevels, pos=[x0, y0], scale=[xscale, yscale]) self.img_view.getView().vb.enableAutoRange(enable=autorange) if self.gl_view is not None: if self.surface is None or data.shape != self.surface._z.shape: x1 = x0 + data.shape[0] * xscale y1 = y0 + data.shape[1] * yscale xs = np.arange(x0, x1, xscale) ys = np.arange(y0, y1, yscale) #grid = gl.GLGridItem() #self.gl_view.addItem(grid) if self.surface is not None: self.gl_view.removeItem(self.surface) self.surface = gl.GLSurfacePlotItem(x=xs, y=ys, shader='shaded') self.gl_view.addItem(self.surface) self.surface.setData(z=data)
def __init__(self, parent=None): super(puff_3D, self).__init__(parent) self.setCameraPosition(distance=150, elevation=30, azimuth=90) image = np.zeros((10, 10)) self.p1 = gl.GLSurfacePlotItem(z=image, shader='heightColor') ## red = pow(z * colorMap[0] + colorMap[1], colorMap[2]) ## green = pow(z * colorMap[3] + colorMap[4], colorMap[5]) ## blue = pow(z * colorMap[6] + colorMap[7], colorMap[8]) self.p1.shader()['colorMap'] = np.array([1, 0, 1, 1, .3, 2, 1, .4, 1]) self.p1.scale(1, 1, 15.0) # self.p1.translate(-puff.udc['paddingXY'], -puff.udc['paddingXY'], 0) self.addItem(self.p1) self.p2 = gl.GLSurfacePlotItem(z=image, shader='heightColor') self.p2.shader()['colorMap'] = np.array([1, 0, 1, 1, .3, 2, 1, .4, 1]) self.p2.scale(1, 1, 15.0) # self.p2.translate(-puff.udc['paddingXY'], -puff.udc['paddingXY'], 0) self.addItem(self.p2) self.shiftx = int(np.ceil(image.shape[0] / 2)) self.p1.translate(self.shiftx, 0, 0) self.p2.translate(-self.shiftx, 0, 0)
def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.setupUi(self) #self.c=Qwt5.QwtPlotCurve() #self.c.attach(self.plt) self.timer = QtCore.QTimer() self.timer.start(5.0) self.timer.timeout.connect(update) self.qtgraph.setLabel('left', 'Voltage', units='V') self.qtgraph.setLabel('bottom', 'Current', units='A') self.c1 = self.qtgraph.plot() self.c1.setPen((200, 200, 100)) ## Add a grid to the 3D view g = gl.GLGridItem() g.scale(2, 2, 1) g.setDepthValue( 10) # draw grid after surfaces since they may be translucent self.pyqt3d.addItem(g) ## Animated example ## compute surface vertex data cols = 90 rows = 100 self.x = np.linspace(-8, 8, cols + 1).reshape(cols + 1, 1) self.y = np.linspace(-8, 8, rows + 1).reshape(1, rows + 1) d = (self.x**2 + self.y**2) * 0.1 d2 = d**0.5 + 0.1 ## precompute height values for all frames phi = np.arange(0, np.pi * 2, np.pi / 20.) self.z = np.sin(d[np.newaxis, ...] + phi.reshape(phi.shape[0], 1, 1)) / d2[np.newaxis, ...] ## create a surface plot, tell it to use the 'heightColor' shader ## since this does not require normal vectors to render (thus we ## can set computeNormals=False to save time when the mesh updates) self.p4 = gl.GLSurfacePlotItem(x=self.x[:, 0], y=self.y[0, :], shader='heightColor', computeNormals=False, smooth=True) self.p4.shader()['colorMap'] = np.array( [0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2]) #self.p4.translate(10, 10, 0) self.pyqt3d.addItem(self.p4) #self.v = gl.GLVolumeItem(d2) #self.v.translate(-50,-50,-100) #self.pyqt3d.addItem(self.v) ax = gl.GLAxisItem() self.pyqt3d.addItem(ax)
def draw_line(x0, x1, y0, y1, z0=1, colors=None): if colors is None: colors = np.ones((4, 3), dtype=float) z = np.full((2, 2), z0) x = np.linspace(x0, x1, 2) y = np.linspace(y0, y1, 2) l = gl.GLSurfacePlotItem(x, y, z=z, colors=colors, shader='shaded', smooth=False) w.addItem(l)
def notify(self, name, value): """ Updates the image rendered to match the model; is able to draw and remove integration highlights. :return: None """ if name == 'integrationUpdate' and value.show is True: self.set_highlight(value) if name == "newIntegration": highlight = gl.GLSurfacePlotItem(computeNormals=False) self.addItem(highlight) highlight.setShader( PaletteShader(self.lower_bound + self.offset, self.upper_bound + self.offset, palette.jet)) highlight.scale(1, 1, 0.00001) self.integrations[value.id] = highlight if name == "showIntegration": if value.show is True: self.set_highlight(value) self.integrations[value.id].setVisible(True) else: self.integrations[value.id].setVisible(False) if name == "removeIntegration": self.removeItem(self.integrations[value.id]) self.integrations.pop(value.id) if name in {'model', 'model.viewTransformed'}: if value is None or value.get_2d_chromatogram_data() is None: self.setVisible(False) else: prev_x, prev_y = self.translation_x, self.translation_y self.translation_x = -len(value.get_2d_chromatogram_data()) / 2 self.translation_y = -len( value.get_2d_chromatogram_data()[0]) / 2 self.surface.translate(self.translation_x - prev_x, self.translation_y - prev_y, 0) self.surface.setData(z=value.get_2d_chromatogram_data()) self.setVisible(True) self.surface.setShader( PaletteShader(value.lower_bound, value.upper_bound, value.palette)) self.lower_bound = value.lower_bound self.upper_bound = value.upper_bound self.offset = self.upper_bound if name == 'model.palette' or name == 'model.lower_bound' or name == 'model.upper_bound': self.surface.setShader( PaletteShader(value.lower_bound, value.upper_bound, value.palette))
def plot_data(self): # for i in range(self.y.shape[0]): # pts = np.vstack((self.x, np.ones_like(self.x) * self.y[i], self.mat[:, i])).T # self.traces.append(gl.GLLinePlotItem(pos=pts, color=pg.glColor( # (i, self.y.shape[0] * 1.3)), width=2, antialias=True)) # self.w.addItem(self.traces[i]) surface = gl.GLSurfacePlotItem(x=self.x, y=self.y, z=self.mat, shader='heightColor', drawEdges=True) surface.shader()['colorMap'] = np.array([0.2, 2, 0.5]) self.w.addItem(surface)
def redraw(self): pw = self.__plot_widget__ pw.items.clear() for key in self.__plot_data__: plot_info = self.__plot_data__[key] if plot_info.visible and (len(plot_info.xs) > 0 and len(plot_info.ys) > 0): pi = gl.GLSurfacePlotItem(x=plot_info.xs, y=plot_info.ys, z=plot_info.zs, color=plot_info.color, shader='shaded') pw.addItem(pi) pw.update()