def __init__(self, parent=None): self.canvas = scene.SceneCanvas( size=(1280, 900), keys="interactive", bgcolor=plot.bg_clr, parent=parent, ) self.grid = self.canvas.central_widget.add_grid(spacing=0) self.view = self.grid.add_view(row=0, col=1, camera="panzoom") self.colormap = color.get_colormap('husl')[np.linspace(0., 1., 24)] self.n = 0 self.lines = {} self.x_axis = scene.AxisWidget(orientation="bottom", text_color="#ddd") self.y_axis = scene.AxisWidget(orientation="left", text_color="#ddd") self.x_axis.stretch = (1, 0.05) self.y_axis.stretch = (0.05, 1) self.grid.add_widget(self.x_axis, row=1, col=1) self.grid.add_widget(self.y_axis, row=0, col=0) self.x_axis.link_view(self.view) self.y_axis.link_view(self.view) self.canvas.show() if parent is None: self.canvas.app.run()
def _configure_2d(self, fg_color=None): if self._configured: return if fg_color is None: fg = self._fg else: fg = fg_color self.yaxis = scene.AxisWidget(orientation='left', text_color=fg, axis_color=fg, tick_color=fg) self.yaxis.stretch = (0.1, 1) self.grid.add_widget(self.yaxis, row=2, col=2) self.ylabel = scene.Label("", rotation=-90) self.ylabel.stretch = (0.05, 1) self.grid.add_widget(self.ylabel, row=2, col=1) self.xaxis = scene.AxisWidget(orientation='bottom', text_color=fg, axis_color=fg, tick_color=fg) self.xaxis.stretch = (1, 0.1) self.grid.add_widget(self.xaxis, row=3, col=3) self.xlabel = scene.Label("") self.xlabel.stretch = (1, 0.05) self.grid.add_widget(self.xlabel, row=4, col=3) self.view.camera = SCTAudioCamera(zoom=None, pan=None) self.camera = self.view.camera self.xaxis.link_view(self.view) self.yaxis.link_view(self.view) self._configured = True
def init_visual_elements(self): self.canvas = scene.SceneCanvas(keys='interactive', show=True) self.grid = self.canvas.central_widget.add_grid(spacing=0) self.viewbox = self.grid.add_view(row=0, col=1, camera='panzoom') # add some axes self.x_axis = scene.AxisWidget(orientation='bottom') self.x_axis.stretch = (1, 0.1) self.grid.add_widget(self.x_axis, row=1, col=1) self.x_axis.link_view(self.viewbox) self.y_axis = scene.AxisWidget(orientation='left') self.y_axis.stretch = (0.1, 1) self.grid.add_widget(self.y_axis, row=0, col=0) self.y_axis.link_view(self.viewbox) # add a line plot inside the viewbox self.line_outline = scene.Line(self._get_robot_outline(), parent=self.viewbox.scene) pathx, pathy = self.path_handler.get_path() path = np.vstack((pathx, pathy)) path = path.T self.line_path = scene.Line(path, parent=self.viewbox.scene) # auto-scale to see the whole line. self.viewbox.camera.set_range() self.t = 0 self.t_max = 10 self.d_t = 0.1 app.Canvas.__init__(self, keys='interactive')
def create_surface(self): N = self.n_samples_to_display color = np.ones((N, 4), dtype=np.float32) color[:, 0] = np.linspace(0, 1, N) color[:, 1] = color[::-1, 0] canvas = scene.SceneCanvas(keys='interactive', show=True) grid = canvas.central_widget.add_grid(spacing=0) self.viewbox = grid.add_view(row=0, col=1, camera='panzoom') x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(self.viewbox) y_axis = scene.AxisWidget(orientation='left') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(self.viewbox) self.setLayout(QVBoxLayout()) self.layout().addWidget(canvas.native) for i in range(0, self.n_channels): pos = np.zeros((N, 2), dtype=np.float32) pos[:, 0] = self.x_mesh[:self.n_samples_to_display] if i: pos[:, 1] = pos[:, 1] + 50*i c = scene.Line(pos, color, parent=self.viewbox.scene) self.curves.append(pos) self.lines.append(c) self.viewbox.camera.set_range()
def __init__(self, name, n, freq): super().__init__() layout = QHBoxLayout() self.setWindowTitle(name) color = np.ones((n, 4), dtype=np.float32) color[:, 0] = np.linspace(0, 1, n) color[:, 1] = color[::-1, 0] canvas = scene.SceneCanvas(keys='interactive', show=True) grid = canvas.central_widget.add_grid(spacing=0) self.viewbox = grid.add_view(row=0, col=1, camera='panzoom') x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(self.viewbox) y_axis = scene.AxisWidget(orientation='left') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(self.viewbox) self.pos = np.zeros((n, 2), dtype=np.float32) self.pos[:, 0] = rfftfreq(n, 1/freq) #pos[:, 0] = self.x_mesh[:self.n_samples_to_display] self.line = scene.Line(self.pos, color, parent=self.viewbox.scene) self.viewbox.camera.set_range() self.freqbar = pg.BarGraphItem(x=[1], height=0, width=0.6, brush='g') self.plot = pg.PlotWidget() self.plot.addItem(self.freqbar) self.plot.setFixedWidth(100) layout.addWidget(canvas.native) layout.addWidget(self.plot) self.setLayout(layout)
def __init__(self, icurves, highlight=None, clrmap='husl', colors=None): """ :param icurves: input curve or list of curves :param clrmap: (optional) what colormap name from vispy.colormap to use :param highlight: (optional) index of a curve to highlight :param colors: (optional) use list of colors instead of colormap """ self.canvas = scene.SceneCanvas(size=(1280, 900), position=(200, 200), keys='interactive', bgcolor=bg_clr) self.grid = self.canvas.central_widget.add_grid(spacing=0) self.view = self.grid.add_view(row=0, col=1, camera='panzoom') curves = np.array(icurves) if len(curves.shape) == 1: ## Single curve curves = np.array([icurves]) nb_traces, size = curves.shape # the Line visual requires a vector of X,Y coordinates xy_curves = np.dstack((np.tile(np.arange(size), (nb_traces, 1)), curves)) # Specify which points are connected # Start by connecting each point to its successor connect = np.empty((nb_traces * size - 1, 2), np.int32) connect[:, 0] = np.arange(nb_traces * size - 1) connect[:, 1] = connect[:, 0] + 1 # Prevent vispy from drawing a line between the last point # of a curve and the first point of the next curve for i in range(size, nb_traces * size, size): connect[i - 1, 1] = i - 1 if highlight is not None: # 'husl' is horrible in this case so we switch to viridis colormap = color.get_colormap('viridis')[np.linspace(0., 1., nb_traces * size)] # cheat by predrawing a single line over the highlighted one scene.Line(pos=xy_curves[highlight], color=colormap[connect.shape[0]-1][0], parent=self.view.scene) scene.Line(pos=xy_curves, color=colormap[connect.shape[0]//2][0], parent=self.view.scene, connect=connect) else: if colors is None: colormap = color.get_colormap(clrmap)[np.linspace(0., 1., nb_traces * size)] else: colormap = color.get_colormap(clrmap)[colors] scene.Line(pos=xy_curves, color=colormap, parent=self.view.scene, connect=connect) self.x_axis = scene.AxisWidget(orientation='bottom') self.y_axis = scene.AxisWidget(orientation='left') self.x_axis.stretch = (1, 0.05) self.y_axis.stretch = (0.05, 1) self.grid.add_widget(self.x_axis, row=1, col=1) self.grid.add_widget(self.y_axis, row=0, col=0) self.x_axis.link_view(self.view) self.y_axis.link_view(self.view) self.view.camera.set_range(x=(-1, size), y=(curves.min(), curves.max())) self.canvas.show() self.canvas.app.run()
def __init__(self, config=None): scene.SceneCanvas.__init__(self, keys=None, config=config) self.unfreeze() back_color = str(QPalette().color(QPalette.Window).name()) self.central_widget.bgcolor = back_color self.central_widget.border_color = back_color grid = self.central_widget.add_grid(margin=10) grid.spacing = 0 top_padding = grid.add_widget(row=0, col=0, col_span=2) top_padding.height_max = 24 yaxis = scene.AxisWidget(orientation='left', axis_color='black', text_color='black', font_size=12) yaxis.width_max = 60 grid.add_widget(yaxis, row=1, col=0) xaxis = scene.AxisWidget(orientation='bottom', axis_color='black', text_color='black', font_size=12) xaxis.height_max = 40 grid.add_widget(xaxis, row=2, col=1) right_padding = grid.add_widget(row=0, col=2, row_span=2) right_padding.width_max = 24 view = grid.add_view(row=1, col=1, border_color='black', bgcolor='white') view.camera = Camera(aspect=1) # Following function was removed from 'prepare_draw()' of 'Grid' class by patch, # it is necessary to call manually grid._update_child_widget_dim() grid1 = scene.GridLines(parent=view.scene, color='gray') grid1.set_gl_state(depth_test=False) xaxis.link_view(view) yaxis.link_view(view) self.grid = grid1 self.view = view self.freeze() self.measure_fps()
def __init__(self): # vertex positions of data to draw N = length self.pos1 = np.zeros((N, 2)) self.pos2 = np.zeros((N, 2)) self.pos1[:, 0] = np.arange(N) / samplerate self.pos2[:, 0] = np.arange(N) / samplerate # color array self.color1 = (1, 0, 0) self.color2 = (0, 1, 0) canvas = scene.SceneCanvas(keys="interactive", show=True) main_grid = canvas.central_widget.add_grid() grid = Grid(border_color="r") info = scene.widgets.ViewBox(border_color="b") info.camera = "panzoom" info.camera.rect = -1, -1, 2, 2 info.stretch = (1, 0.1) main_grid.add_widget(grid, row=0, col=0) main_grid.add_widget(info, row=1, col=0) # add some axes x_axis = scene.AxisWidget(orientation="bottom") x_axis.stretch = (1, 0.1) y_axis = scene.AxisWidget(orientation="left") y_axis.stretch = (0.1, 1) grid.add_widget(x_axis, row=1, col=1) grid.add_widget(y_axis, row=0, col=0) viewbox = grid.add_view(row=0, col=1, camera="panzoom") x_axis.link_view(viewbox) y_axis.link_view(viewbox) # add cpu information text = Text(text="TEXT", color=(1, 1, 1, 1), parent=info.scene) text.font_size = 18 self.text = text # add a line plot inside the viewbox self.line1 = scene.Line(self.pos1, self.color1, parent=viewbox.scene) self.line2 = scene.Line(self.pos2, self.color2, parent=viewbox.scene) # auto-scale to see the whole line. viewbox.camera.set_range()
def _setup_yaxis(self, ylabel): self.ylabel = scene.Label(ylabel.text, font_size=ylabel.font_size, color=ylabel.color, rotation=-90) ylabel_widget = self.grid.add_widget(self.ylabel, row=0, col=0) ylabel_widget.width_max = ylabel.dim self.yaxis = scene.AxisWidget(orientation='left', text_color=ylabel.color, axis_color=ylabel.color, tick_color=ylabel.color, ) yaxis_widget = self.grid.add_widget(self.yaxis, row=0, col=1) yaxis_widget.width_max = ylabel.dim
def attach_yaxis(self, axis_color=(0, 1, 1, 0.8)): ''' Provide y axis for the population rate ''' fg = axis_color # text show amplitude self.amp_text = scene.Text("", pos=(0, 0), italic=False, bold=False, anchor_x='left', anchor_y='center', color=axis_color, font_size=10, parent=self._view2) self.amp_text.pos = (0, 20) # x axis shows time and can be moved horizontally for clipping self._yaxis = scene.AxisWidget(orientation='left', text_color=fg, axis_color=fg, tick_color=fg) self._yaxis.stretch = (0, 1) self._grid.add_widget(self._yaxis, row=10, col=0, row_span=3) self._yaxis.link_view(self._view2)
def _setup_xaxis(self, xlabel): self.xaxis = scene.AxisWidget(orientation='bottom', text_color=xlabel.color, axis_color=xlabel.color, tick_color=xlabel.color) xaxis_widget = self.grid.add_widget(self.xaxis, row=1, col=2) xaxis_widget.height_max = xlabel.dim self.xlabel = scene.Label(xlabel.text, font_size=xlabel.font_size, color=xlabel.color) xlabel_widget = self.grid.add_widget(self.xlabel, row=2, col=2) xlabel_widget.height_max = xlabel.dim
def attach_xaxis(self, axis_color=(0, 1, 1, 0.8)): ''' Provide x axis. This method is optional for child class. ''' fg = axis_color # text show amplitude self.amp_text = scene.Text("", pos=(0, 0), italic=False, bold=False, anchor_x='left', anchor_y='center', color=axis_color, font_size=15, parent=self._view) self.amp_text.pos = (0, 12) # x axis shows time and can be moved horizontally for clipping self._xaxis = scene.AxisWidget(orientation='bottom', text_color=fg, axis_color=fg, tick_color=fg) self._xaxis.stretch = (0.9, 0.1) self._grid.add_widget(self._xaxis, row=7, col=0, row_span=2) self._xaxis.link_view(self._view) self.x_axis_lock = True
def __init__(self, curves=None, labels=None, bgcolor=BG_DARK, parent=None, dontrun=False): """ :param icurves: input curve or list of curves :param clrmap: (optional) what colormap name from vispy.colormap to use """ self.canvas = scene.SceneCanvas( size=(1280, 900), position=(200, 200), keys="interactive", bgcolor=bgcolor, parent=parent, ) self.line = None self.grid = self.canvas.central_widget.add_grid(spacing=0) self.x_axis = scene.AxisWidget(orientation="bottom") self.y_axis = scene.AxisWidget(orientation="left") self.x_axis.stretch = (1, 0.05) self.y_axis.stretch = (0.05, 1) self.grid.add_widget(self.x_axis, row=1, col=1) self.grid.add_widget(self.y_axis, row=0, col=0) self.view = self.grid.add_view(row=0, col=1, camera="panzoom") self.x_axis.link_view(self.view) self.y_axis.link_view(self.view) self.ctrl_pressed = False self.shift_pressed = False self.canvas.connect(self.on_key_press) self.canvas.connect(self.on_key_release) self.canvas.connect(self.on_mouse_press) self.canvas.connect(self.on_mouse_release) self.canvas.connect(self.on_mouse_move) if curves is not None: self.draw_curves(curves, labels) self.canvas.show() if parent is None and dontrun is False: self.canvas.app.run()
def _configure_2d(self, fg_color=None): if self._configured: return if fg_color is None: fg = self._fg else: fg = fg_color # +-------+-------+ # | yaxis | view | # |-------+-------+ # | | xaxis | # +-------+-------+ # row 0 # yaxis - column 0 # view - column 1 self.yaxis = scene.AxisWidget(orientation='left', text_color=fg, axis_color=fg, tick_color=fg) yaxis_widget = self.grid.add_widget(self.yaxis, row=0, col=0) yaxis_widget.width_max = 40 self.view = self.grid.add_view(row=0, col=1, border_color='grey', bgcolor="#efefef") self.view.camera = 'panzoom' self.camera = self.view.camera # row 1 # xaxis - column 1 self.xaxis = scene.AxisWidget(orientation='bottom', text_color=fg, axis_color=fg, tick_color=fg) xaxis_widget = self.grid.add_widget(self.xaxis, row=1, col=1) xaxis_widget.height_max = 40 self._configured = True self.xaxis.link_view(self.view) self.yaxis.link_view(self.view)
def init_axes(self, **kwargs): self.grid = self.canvas.central_widget.add_grid(margin=10) self.grid.spacing = 0 self.r = 0 self.title = scene.Label(kwargs.get("title", ""), color="w") self.title.height_max = 40 self.grid.add_widget(self.title, row=0, col=0, col_span=2) self.r += 1 self.yaxis = scene.AxisWidget( orientation="left", axis_label=kwargs.get("y_label", ""), axis_font_size=10, axis_label_margin=40, #20? tick_label_margin=15, ) self.yaxis.width_max = 80 self.grid.add_widget(self.yaxis, row=self.r, col=0) self.xaxis = scene.AxisWidget( orientation="bottom", axis_label=kwargs.get("x_label", ""), axis_font_size=10, axis_label_margin=40, tick_label_margin=15, ) self.xaxis.height_max = 80 self.grid.add_widget(self.xaxis, row=self.r + 1, col=1) right_padding = self.grid.add_widget(row=self.r, col=2, row_span=1) right_padding.width_max = 50 self.view = self.grid.add_view(row=self.r, col=1, border_color="white") self.view.camera = "panzoom" self.view.camera.set_default_state() self.xaxis.link_view(self.view) self.yaxis.link_view(self.view)
def add_axis(self, axis_color=(0, 1, 1, 0.8)): fg = axis_color self.unfreeze() self.yaxis = scene.AxisWidget(orientation='left', text_color=fg, axis_color=fg, tick_color=fg) self.yaxis.stretch = (0.1, 0.9) self.grid.add_widget(self.yaxis, row=0, col=0) self.xaxis = scene.AxisWidget(orientation='bottom', text_color=fg, axis_color=fg, tick_color=fg) self.xaxis.stretch = (0.9, 0.1) self.grid.add_widget(self.xaxis, row=1, col=1) self.xaxis.link_view(self.view) self.yaxis.link_view(self.view) self.freeze()
def __init__(self, axis=True, x_label='', x_heightMax=40, font_size=12, color='white', title='', axis_label_margin=50, tick_label_margin=5, name='', bgcolor=(.9, .9, .9), cargs={}, xargs={}, indic_color='darkred', fcn=[]): # Create the main canvas : self.canvas = scene.SceneCanvas(keys=None, bgcolor=bgcolor, show=False, title=name, **cargs) _ = [self.canvas.connect(k) for k in fcn] # Create a grid : grid = self.canvas.central_widget.add_grid(margin=0) grid.spacing = 0 # Add x-axis : self.xaxis = scene.AxisWidget(orientation='bottom', axis_label=x_label, axis_font_size=font_size, axis_label_margin=axis_label_margin, tick_label_margin=tick_label_margin, **xargs) self.xaxis.height_max = x_heightMax grid.add_widget(self.xaxis, row=1, col=0) # Main plot : self.wc = grid.add_view(row=0, col=0, border_color=color) # Add a square indicator : image = color2vb(indic_color)[np.newaxis, ...] self.mesh = scene.visuals.Image(image, name='indicator') self.mesh.parent = self.wc.scene # Add markers : pos = np.full((1, 3), -10, dtype=np.float32) self.markers = Markers(pos=pos, parent=self.wc.scene) self.markers.set_gl_state('translucent')
def __init__(self, axis=True, x_label='', name='', use_pad=False, bgcolor='white', fcn=[]): """Init.""" # Save variables : self._axis = axis # Create the main canvas : self.canvas = scene.SceneCanvas(keys=None, bgcolor=bgcolor, show=False, title=name) _ = [self.canvas.connect(k) for k in fcn] # noqa # Add axis : if axis: # Create a grid : grid = self.canvas.central_widget.add_grid(margin=0) # Add y-axis : if use_pad: pad = grid.add_widget(row=1, col=0) pad.width_max = 50 else: self.yaxis = scene.AxisWidget(orientation='left', text_color='black') self.yaxis.width_max = 50 grid.add_widget(self.yaxis, row=1, col=0) # Add right padding : bottom_pad = grid.add_widget(row=2, col=0, row_span=1) bottom_pad.height_max = 10 top_pad = grid.add_widget(row=0, col=0, row_span=1) top_pad.height_max = 10 # Main plot : self.wc = grid.add_view(row=1, col=1, border_color='white') # Ignore axis : else: self.wc = self.canvas.central_widget.add_view()
def __init__(self, axis=True, x_label='', name='', bgcolor=(1., 1., 1.), indic_color='darkred', fcn=[]): """Init.""" # Create the main canvas : self.canvas = scene.SceneCanvas(keys=None, bgcolor=bgcolor, show=False) _ = [self.canvas.connect(k) for k in fcn] # noqa # Create a grid : grid = self.canvas.central_widget.add_grid(margin=0) grid.spacing = 0 # Add x-axis : self.xaxis = scene.AxisWidget(orientation='bottom', text_color='black') if axis: pad = grid.add_widget(row=0, col=0) pad.width_max = 50 _col = int(axis) grid.add_widget(self.xaxis, row=1, col=_col) # Main plot : self.wc = grid.add_view(row=0, col=_col, border_color='black') # Add a square indicator : image = color2vb(indic_color)[np.newaxis, ...] self.mesh = scene.visuals.Image(image, name='Time indicator') self.mesh.transform = vist.STTransform() self.mesh.parent = self.wc.scene # Add markers : pos = np.full((1, 3), -10, dtype=np.float32) self.markers = Markers(pos=pos, parent=self.wc.scene) self.markers.set_gl_state('translucent')
y_lim = [-2., 2.] pos[:, 0] = np.linspace(x_lim[0], x_lim[1], N) pos[:, 1] = np.random.normal(size=N) # color array color = np.ones((N, 4), dtype=np.float32) color[:, 0] = np.linspace(0, 1, N) color[:, 1] = color[::-1, 0] canvas = scene.SceneCanvas(keys='interactive', show=True) grid = canvas.central_widget.add_grid(spacing=0) viewbox = grid.add_view(row=0, col=1, camera='panzoom') # add some axes x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(viewbox) y_axis = scene.AxisWidget(orientation='left') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(viewbox) # add a line plot inside the viewbox line = scene.Line(pos, color, parent=viewbox.scene) # auto-scale to see the whole line. viewbox.camera.set_range()
def __init__(self, graph_index=None, graph_time=None, graph_position=None, graph_error=None, graph_fan=None, graph_target=None): self.graph_index, self.graph_time, self.graph_position, self.graph_error, self.graph_fan, self.graph_target = graph_index, graph_time, graph_position, graph_error, graph_fan, graph_target self.last_graph_index = graph_index.value - 1 self.line_opacity = 0.8 self.data_pos = np.zeros((0, 2), dtype=np.float32) self.data_pos_error = np.zeros((0, 2), dtype=np.float32) self.color = np.ones((0, 4), dtype=np.float32) self.data_fan = np.zeros((0, 2), dtype=np.float32) self.data_target = np.zeros((0, 2), dtype=np.float32) self.canvas = scene.SceneCanvas( keys='interactive', show=True, title='Ping-Pong Ball PID Oscilloscope') grid = self.canvas.central_widget.add_grid(spacing=0) #https://github.com/vispy/vispy/blob/master/vispy/scene/cameras/panzoom.py self.viewbox_fan = grid.add_view(row=0, col=1, camera='panzoom', parent=self.canvas.scene) self.viewbox_pos = grid.add_view(row=0, col=1, camera='panzoom', parent=self.canvas.scene) self.viewbox_pos.events.resize.connect(self.on_resize) # add some axes x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(self.viewbox_pos) y_axis = scene.AxisWidget(orientation='left', text_color='red') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(self.viewbox_pos) y2_axis = scene.AxisWidget(orientation='right', text_color='green') y2_axis.stretch = (0.1, 10) grid.add_widget(y2_axis, row=0, col=2) y2_axis.link_view(self.viewbox_fan) # y2_axis.transform = STTransform(scale=(1, 0.2, 1)) t1 = Text('Detected Ball Position [m]', parent=self.canvas.scene, color='red') t1.font_size = 10 # t1.pos = self.canvas.size[0] // 2, self.canvas.size[1] // 3 t1.pos = 167, 20 t2 = Text('Detected Ball Position Error [m]', parent=self.canvas.scene, color='yellow') t2.font_size = 10 t2.pos = 185, 35 t3 = Text('Fan RPM [RPM]', parent=self.canvas.scene, color='green') t3.font_size = 10 t3.pos = 130, 50 t4 = Text('Target Height [m]', parent=self.canvas.scene, color='blue') t4.font_size = 10 t4.pos = 135, 65 # add a line plot inside the viewbox self.line_pos = None self.line_pos_error = None self.line_target = None self.line_fan = None # add horizontal lines scene.InfiniteLine(0.0, [0.5, 0.5, 0.5, 0.5], vertical=False, parent=self.viewbox_pos.scene) # auto-scale to see the whole line. self.viewbox_pos.camera.set_range() self.auto_scale = True self.auto_scroll = False self.canvas.events.mouse_press.connect(self.on_mouse_press) self.canvas.events.mouse_release.connect(self.on_mouse_release) self.canvas.events.key_press.connect(self.on_key_press) return
import sys import numpy as np from vispy import scene, app canvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True) grid = canvas.central_widget.add_grid(margin=10) grid.spacing = 0 title = scene.Label("Plot Title", color='white') title.height_max = 40 grid.add_widget(title, row=0, col=0, col_span=2) yaxis = scene.AxisWidget(orientation='left', axis_label='Y Axis', axis_font_size=12, axis_label_margin=50, tick_label_margin=5) yaxis.width_max = 80 grid.add_widget(yaxis, row=1, col=0) xaxis = scene.AxisWidget(orientation='bottom', axis_label='X Axis', axis_font_size=12, axis_label_margin=50, tick_label_margin=5) xaxis.height_max = 80 grid.add_widget(xaxis, row=2, col=1) right_padding = grid.add_widget(row=1, col=2, row_span=1)
# Copyright (c) Vispy Development Team. All Rights Reserved. # Distributed under the (new) BSD License. See LICENSE.txt for more info. # vispy: gallery 30 """ Show 10,000 realtime scrolling plots """ from vispy import app, scene import numpy as np canvas = scene.SceneCanvas(keys='interactive', show=True, size=(1024, 768)) grid = canvas.central_widget.add_grid() view = grid.add_view(0, 1) view.camera = scene.MagnifyCamera(mag=1, size_factor=0.5, radius_ratio=0.6) # Add axes yax = scene.AxisWidget(orientation='left') yax.stretch = (0.05, 1) grid.add_widget(yax, 0, 0) yax.link_view(view) xax = scene.AxisWidget(orientation='bottom') xax.stretch = (1, 0.05) grid.add_widget(xax, 1, 1) xax.link_view(view) N = 4900 M = 2000 cols = int(N**0.5) view.camera.rect = (0, 0, cols, N / cols) lines = scene.ScrollingLines(n_lines=N,
def __init__( self, parent=None, rows=None, cols=None, xlim=[-1, 1], ylim=[-1, 1], view_options=None, plot_options=None, projection=None, x_axis_options=None, y_axis_options=None, ): super().__init__(parent=parent) if isinstance(rows, slice) and isinstance(cols, slice): row, row_span = rows.start, rows.stop - rows.start col, col_span = cols.start, cols.stop - cols.start else: row = col = None row_span = col_span = 1 self.view, row, col = self.parent._get_subplot( row, col, row_span, col_span, view_options ) self.view.camera = CustomPanZoomCamera( rect=(xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0]), interactive=False, ) plot_options = {} if plot_options is None else plot_options plot_options.setdefault("parent", self.view.scene) self.scatter = scene.visuals.Markers(**plot_options) if projection == "3d": self.scatter.set_data(np.zeros((1, 3))) self.view.camera = "turntable" self.axis = scene.visuals.XYZAxis(parent=self.view.scene) else: if y_axis_options is not None: y_axis_options.setdefault("orientation", "right") y_axis_options.setdefault("axis_font_size", 12) y_axis_options.setdefault("axis_label_margin", 50) y_axis_options.setdefault("tick_label_margin", 5) self.yaxis = scene.AxisWidget(**y_axis_options) self.parent.grid.add_widget( self.yaxis, row=row, col=col, row_span=row_span, col_span=col_span ) self.yaxis.link_view(self.view) if x_axis_options is not None: x_axis_options.setdefault("orientation", "top") x_axis_options.setdefault("axis_font_size", 12) x_axis_options.setdefault("axis_label_margin", 50) x_axis_options.setdefault("tick_label_margin", 5) self.xaxis = scene.AxisWidget(**x_axis_options) self.parent.grid.add_widget( self.xaxis, row=row, col=col, row_span=row_span, col_span=col_span ) self.xaxis.link_view(self.view)
def _configure_2d(self, fg_color=None): if self._configured: return if fg_color is None: fg = self._fg else: fg = fg_color # c0 c1 c2 c3 c4 c5 c6 # r0 +---------+-------+-------+-------+-------+---------+---------+ # | | | title | | | # r1 | +-----------------------+-------+---------+ | # | | | cbar | | | # r2 | +-------+-------+-------+-------+---------+ | # | | cbar | ylabel| yaxis | view | cbar | padding | # r3 | padding +-------+-------+-------+-------+---------+ | # | | | xaxis | | | # r4 | +-----------------------+-------+---------+ | # | | | xlabel| | | # r5 | +-----------------------+-------+---------+ | # | | | cbar | | | # r6 |---------+-----------------------+-------+---------+---------| # | padding | # +---------+-----------------------+-------+---------+---------+ default = False get_func = CONF.get_default if default else CONF.get section = 'image_viewer' padding_left_width = get_func(section, 'padding_left_width') padding_right_width = get_func(section, 'padding_right_width') padding_bottom_height = get_func(section, 'padding_bottom_height') cbar_top_height = get_func(section, 'cbar_top_height') cbar_bottom_height = get_func(section, 'cbar_bottom_height') cbar_left_width = get_func(section, 'cbar_left_width') cbar_right_width = get_func(section, 'cbar_right_width') title_widget_height = get_func(section, 'title_widget_height') xlabel_widget_height = get_func(section, 'xlabel_widget_height') ylabel_widget_width = get_func(section, 'ylabel_widget_width') xaxis_widget_height = get_func(section, 'xaxis_widget_height') yaxis_widget_width = get_func(section, 'yaxis_widget_width') # padding left padding_left = self.grid.add_widget(None, row=0, row_span=5, col=0) padding_left.width_min = padding_left_width[0] padding_left.width_max = padding_left_width[1] # padding right padding_right = self.grid.add_widget(None, row=0, row_span=5, col=6) padding_right.width_min = padding_right_width[0] padding_right.width_max = padding_right_width[1] # padding right padding_bottom = self.grid.add_widget(None, row=6, col=0, col_span=6) padding_bottom.height_min = padding_bottom_height[0] padding_bottom.height_max = padding_bottom_height[1] # row 0 # title - column 4 to 5 self.title_widget = self.grid.add_widget(self.title, row=0, col=4) self.title_widget.height_min = title_widget_height[0] self.title_widget.height_max = title_widget_height[1] # row 1 # colorbar - column 4 to 5 self.cbar_top = self.grid.add_widget(None, row=1, col=4) self.cbar_top.height_max = cbar_top_height[1] # row 2, xlabel # xlabel - column 4 self.xlabel = scene.Label("xlabel") xlabel_widget = self.grid.add_widget(self.xlabel, row=2, col=4) xlabel_widget.height_min = xlabel_widget_height[0] xlabel_widget.height_max = xlabel_widget_height[1] # row 3, xaxis # row 4 # colorbar_left - column 1 # ylabel - column 2 # yaxis - column 3 # view - column 4 # colorbar_right - column 5 self.cbar_left = self.grid.add_widget(None, row=4, col=1) self.cbar_left.width_max = cbar_left_width[1] self.ylabel = scene.Label("ylabel", rotation=-90) ylabel_widget = self.grid.add_widget(self.ylabel, row=4, col=2) ylabel_widget.width_min = ylabel_widget_width[0] ylabel_widget.width_max = ylabel_widget_width[1] self.yaxis = scene.AxisWidget(orientation='left', text_color=fg, axis_color=fg, tick_color=fg) yaxis_widget = self.grid.add_widget(self.yaxis, row=4, col=3) yaxis_widget.width_min = yaxis_widget_width[0] yaxis_widget.width_max = yaxis_widget_width[0] self.view = self.grid.add_view(row=4, col=4, border_color='grey', bgcolor="#efefef") self.view.camera = 'panzoom' self.camera = self.view.camera self.cbar_right = self.grid.add_widget(None, row=4, col=5) self.cbar_right.width_max = cbar_right_width[1] # row 3 # xaxis - column 4 self.xaxis = scene.AxisWidget(orientation='top', text_color=fg, axis_color=fg, tick_color=fg) xaxis_widget = self.grid.add_widget(self.xaxis, row=3, col=4) xaxis_widget.height_min = xaxis_widget_height[0] xaxis_widget.height_max = xaxis_widget_height[1] # row 4 # xlabel - column 4 # self.xlabel = scene.Label("xlabel") # xlabel_widget = self.grid.add_widget(self.xlabel, row=4, col=4) # xlabel_widget.height_min = 20 # xlabel_widget.height_max = 40 # row 5 self.cbar_bottom = self.grid.add_widget(None, row=5, col=4) self.cbar_bottom.height_max = cbar_bottom_height[1] self._configured = True self.xaxis.link_view(self.view) self.yaxis.link_view(self.view)
def __init__(self, keys='interactive', size=(1024, 768), **kwargs): super().__init__(keys=keys, size=size, **kwargs) self.unfreeze() self._grid = self.central_widget.add_grid(spacing=0, border_color='k', border_width=2, margin=0) self._viewbox = self._grid.add_view(row=0, col=1, camera='panzoom', border_color='k', margin=0, border_width=2, bgcolor=(0.99, 0.99, 0.99, 1)) # add some axes self._xAxis = scene.AxisWidget(orientation='bottom', axis_label='X Axis', font_size=10, axis_color='k', tick_color='k', text_color='k', tick_label_margin=20, axis_label_margin=30) self._xAxis.stretch = (1, 0.1) self._grid.add_widget(self._xAxis, row=1, col=1) self._xAxis.link_view(self._viewbox) self._yAxis = scene.AxisWidget(orientation='left', axis_label='Y Axis', font_size=10, axis_color='k', tick_color='k', text_color='k') self._yAxis.stretch = (0.1, 1) self._grid.add_widget(self._yAxis, row=0, col=0) self._yAxis.link_view(self._viewbox) self._gridLines = scene.GridLines(color=(0, 0, 0, 1), parent=self._viewbox.scene) self._xLine = scene.Line(color='r', width=2, parent=self._viewbox.scene) self._yLine = scene.Line(color='b', width=2, parent=self._viewbox.scene) self._zLine = scene.Line(color='g', width=2, parent=self._viewbox.scene) self._gridLines.set_gl_state('translucent', cull_face=False) self._xLine.set_gl_state(depth_test=False) self._yLine.set_gl_state(depth_test=False) self._zLine.set_gl_state(depth_test=False) self._pointNum = 3000 self._timeLine = 5.0 self._xAxisLim = [0., self._timeLine] self._yAxisLim = [-1., 1.] self._xPos = np.array([ [0, 0], ], dtype=np.float32) # np.zeros((self._pointNum, 2), dtype=np.float32) self._yPos = np.array([ [0, 0], ], dtype=np.float32) self._zPos = np.array([ [0, 0], ], dtype=np.float32) self.freeze() self.show()
def __init__(self, spectra_colors=("r", "g"), y_axis='Src. Lag', bgcolor="#353535"): #some default dummy values self.filenames = () self.props = None self.vmin = -80 self.vmax = -40 self.num_cores = os.cpu_count() self.fft_size = 1024 self.hop = 256 self.sr = 44100 self.num_ffts = 0 scene.SceneCanvas.__init__(self, keys="interactive", size=(1024, 512), bgcolor=bgcolor) self.unfreeze() grid = self.central_widget.add_grid(margin=10) grid.spacing = 0 #speed chart self.speed_yaxis = scene.AxisWidget(orientation='left', axis_label=y_axis, axis_font_size=8, axis_label_margin=35, tick_label_margin=5) self.speed_yaxis.width_max = 55 #spectrum self.spec_yaxis = vispy_ext.ExtAxisWidget(orientation='left', axis_label='Hz', axis_font_size=8, axis_label_margin=35, tick_label_margin=5, scale_type="logarithmic") self.spec_yaxis.width_max = 55 self.spec_xaxis = scene.AxisWidget(orientation='bottom', axis_label='sec', axis_font_size=8, axis_label_margin=35, tick_label_margin=5) self.spec_xaxis.height_max = 55 top_padding = grid.add_widget(row=0) top_padding.height_max = 10 right_padding = grid.add_widget(row=1, col=2, row_span=1) right_padding.width_max = 70 #create the color bar display self.colorbar_display = scene.ColorBarWidget(label="Gain [dB]", clim=(self.vmin, self.vmax), cmap="viridis", orientation="right", border_width=1, label_color="white") self.colorbar_display.label.font_size = 8 self.colorbar_display.ticks[0].font_size = 8 self.colorbar_display.ticks[1].font_size = 8 grid.add_widget(self.speed_yaxis, row=1, col=0) grid.add_widget(self.spec_yaxis, row=2, col=0) grid.add_widget(self.spec_xaxis, row=3, col=1) colorbar_column = grid.add_widget(self.colorbar_display, row=2, col=2) self.speed_view = grid.add_view(row=1, col=1, border_color='white') self.speed_view.camera = vispy_ext.PanZoomCameraExt(rect=(0, -5, 10, 10), ) self.speed_view.height_min = 150 self.spec_view = grid.add_view(row=2, col=1, border_color='white') self.spec_view.camera = vispy_ext.PanZoomCameraExt(rect=(0, 0, 10, 10), ) #link them, but use custom logic to only link the x view self.spec_view.camera.link(self.speed_view.camera) self.speed_yaxis.link_view(self.speed_view) self.spec_xaxis.link_view(self.spec_view) self.spec_yaxis.link_view(self.spec_view) self.spectra = [ Spectrum(self.spec_view, overlay=color) for color in spectra_colors ] self.init_fft_storages() #nb. this is a vispy.util.event.EventEmitter object #can this be linked somewhere to the camera? base_camera connects a few events, too for spe in self.spectra: self.spec_view.transforms.changed.connect(spe.update_frustum) self.freeze()
def __init__(self, parent): super(SignalWidget, self).__init__(parent) # Useful trnascripts self.plugin = self.parent() self.sd = self.plugin.sd self.CONF_SECTION = self.parent().CONF_SECTION # Variables self.measurement_mode = False self.curr_pc = None self.sig_start = None self.sig_stop = None self.spect_type = 'spectrum' # spectrum, spectrogram # General variables self.low_lim = None self.high_lim = None # Sepctrum variables self.mean_filter = None # Setup camera self.signal_camera = SignalCamera() self.spectrum_camera = SignalCamera() self.canvas = scene.SceneCanvas(show=True, keys='interactive', parent=self, bgcolor=CONF.get( self.CONF_SECTION, 'bgcolor')) self.view_grid = self.canvas.central_widget.add_grid(margin=10) # Signal self.signal_view = self.view_grid.add_view(row=0, col=1, row_span=2, camera=self.signal_camera) axis_color = CONF.get(self.CONF_SECTION, 'axis_color') self.signal_yaxis = AxisWidget(orientation='left', axis_label='Amplitude', axis_font_size=12, tick_label_margin=5, axis_color=axis_color, tick_color=axis_color, text_color=axis_color) self.signal_yaxis.width_max = 60 self.view_grid.add_widget(self.signal_yaxis, row=0, col=0, row_span=2) self.signal_xaxis = scene.AxisWidget(orientation='bottom', axis_label='Time [s]', axis_font_size=12, tick_label_margin=5, axis_color=axis_color, tick_color=axis_color, text_color=axis_color) self.signal_xaxis.height_max = 55 self.view_grid.add_widget(self.signal_xaxis, row=2, col=1) self.signal_yaxis.link_view(self.signal_view) self.signal_xaxis.link_view(self.signal_view) # Spectrum self.spectrum_view = self.view_grid.add_view( row=3, col=1, row_span=2, camera=self.spectrum_camera) self.spectrum_yaxis = AxisWidget(orientation='left', axis_label='Amplitude', axis_font_size=12, tick_label_margin=5, axis_color=axis_color, tick_color=axis_color, text_color=axis_color) self.spectrum_yaxis.width_max = 60 self.view_grid.add_widget(self.spectrum_yaxis, row=3, col=0, row_span=2) self.spectrum_xaxis = scene.AxisWidget(orientation='bottom', axis_label='Frequency [Hz]', axis_font_size=12, axis_color=axis_color, tick_color=axis_color, text_color=axis_color) self.spectrum_xaxis.height_max = 55 self.view_grid.add_widget(self.spectrum_xaxis, row=5, col=1) self.spectrum_yaxis.link_view(self.spectrum_view) self.spectrum_xaxis.link_view(self.spectrum_view) self.signal_line = Line(parent=self.signal_view.scene, width=1) self.spectrum_line = Line(parent=self.spectrum_view.scene, width=1) self.spectrogram = Spectrogram([0], parent=self.spectrum_view.scene) # ----- Set layout ----- # Widget layout layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.canvas.native) # Set the whole layout self.setLayout(layout)
def __init__(self, axis=False, title=None, xlabel=None, ylabel=None, title_font_size=15., axis_font_size=12., axis_color='black', tick_font_size=10., name=None, x_height_max=80, y_width_max=80, axis_label_margin=50, tick_label_margin=5, rpad=20., bgcolor='white', add_cbar=False, cargs={}, xargs={}, yargs={}, cbargs={}, show=False, camera=None, shortcuts={}): """Init.""" self._axis = axis self._title = title self._xlabel = xlabel self._ylabel = ylabel self._title_font_size = title_font_size self._axis_font_size = axis_font_size self._axis_color = axis_color self._tick_font_size = tick_font_size self._name = name self._x_height_max = x_height_max self._y_width_max = y_width_max self._axis_label_margin = axis_label_margin self._tick_label_margin = tick_label_margin self._bgcolor = bgcolor self._visible = show # ########################## MAIN CANVAS ########################## self.canvas = scene.SceneCanvas(keys='interactive', bgcolor=bgcolor, show=show, title=name, **cargs) # ########################## AXIS ########################## if axis: # add axis to canvas # ----------- GRID ----------- grid = self.canvas.central_widget.add_grid(margin=10) grid.spacing = 0 # ----------- COLOR ----------- axcol = color2vb(axis_color) kw = { 'axis_label_margin': axis_label_margin, 'tick_label_margin': tick_label_margin, 'axis_font_size': axis_font_size, 'axis_color': axcol, 'tick_color': axcol, 'text_color': axcol, 'tick_font_size': tick_font_size } # ----------- TITLE ----------- self._titleObj = scene.Label(title, color=axcol, font_size=title_font_size) self._titleObj.height_max = 40 grid.add_widget(self._titleObj, row=0, col=0, col_span=2) # ----------- Y-AXIS ----------- yargs.update(kw) self.yaxis = scene.AxisWidget(orientation='left', domain=(0, 129), axis_label=ylabel, **yargs) self.yaxis.width_max = y_width_max grid.add_widget(self.yaxis, row=1, col=0) # ----------- X-AXIS ----------- xargs.update(kw) self.xaxis = scene.AxisWidget(orientation='bottom', axis_label=xlabel, **xargs) self.xaxis.height_max = x_height_max grid.add_widget(self.xaxis, row=2, col=1) # ----------- MAIN ----------- self.wc = grid.add_view(row=1, col=1, camera=camera) self.grid = grid # ----------- LINK ----------- self.xaxis.link_view(self.wc) self.yaxis.link_view(self.wc) # ----------- CBAR ----------- rpad_col = 0 if add_cbar: self.wc_cbar = grid.add_view(row=1, col=2) self.wc_cbar.width_max = 150. self.cbar = CbarVisual(width=.2, parent=self.wc_cbar.scene) rpad_col += 1 # ----------- RIGHT PADDING ----------- self._rpad = grid.add_widget(row=1, col=2 + rpad_col, row_span=1) self._rpad.width_max = rpad else: # Ignore axis self.wc = self.canvas.central_widget.add_view(camera=camera)
def __init__( self, parent=None, rows=None, cols=None, num_lines=1, window_size=1000, ylim=[-1.2, 1.2], view_options=None, plot_options=None, x_axis_options=None, y_axis_options=None, ): super().__init__(parent=parent) if isinstance(rows, slice) and isinstance(cols, slice): row, row_span = rows.start, rows.stop - rows.start col, col_span = cols.start, cols.stop - cols.start else: row = col = None row_span = col_span = 1 self.view, row, col = self.parent._get_subplot( row, col, row_span, col_span, view_options ) self.view.camera = CustomPanZoomCamera( rect=(0, ylim[0], window_size, ylim[1] - ylim[0]), interactive=False ) plot_options = {} if plot_options is None else plot_options plot_options.setdefault("antialias", False) plot_options.setdefault("method", "gl") plot_options.setdefault("parent", self.view.scene) self.window_size = window_size x = np.arange(window_size) y = np.zeros(window_size) self.lines = [ scene.visuals.Line(np.stack((x, y), axis=1), **plot_options) for _ in range(num_lines) ] self.steps = np.zeros(num_lines, dtype=np.int32) if y_axis_options is not None: y_axis_options.setdefault("orientation", "right") y_axis_options.setdefault("axis_font_size", 12) y_axis_options.setdefault("axis_label_margin", 50) y_axis_options.setdefault("tick_label_margin", 5) self.yaxis = scene.AxisWidget(**y_axis_options) self.parent.grid.add_widget( self.yaxis, row=row, col=col, row_span=row_span, col_span=col_span ) self.yaxis.link_view(self.view) if x_axis_options is not None: x_axis_options.setdefault("orientation", "top") x_axis_options.setdefault("axis_font_size", 12) x_axis_options.setdefault("axis_label_margin", 50) x_axis_options.setdefault("tick_label_margin", 5) self.xaxis = scene.AxisWidget(**x_axis_options) self.parent.grid.add_widget( self.xaxis, row=row, col=col, row_span=row_span, col_span=col_span ) self.xaxis.link_view(self.view)