def __init__(self): self.chunksize = 1024 self.rate = rate = 44100 t = np.linspace(0, 10, rate*10) self.data = (np.sin(t * 10.) * 0.3).astype('float32') self.data += np.sin((t + 0.3) * 20.) * 0.15 self.data += gaussian_filter(np.random.normal(size=self.data.shape) * 0.2, (0.4, 8)) self.data += gaussian_filter(np.random.normal(size=self.data.shape) * 0.005, (0, 1)) self.data += np.sin(t * 1760 * np.pi) # 880 Hz self.data = (self.data * 2**10 - 2**9).astype('int16') self.ptr = 0
def __init__(self): self.chunksize = 1024 self.rate = rate = 44100. t = np.linspace(0, 10, rate*10) self.data = (np.sin(t * 10.) * 0.3).astype('float32') self.data += np.sin((t + 0.3) * 20.) * 0.15 self.data += gaussian_filter(np.random.normal(size=self.data.shape) * 0.2, (0.4, 8)) self.data += gaussian_filter(np.random.normal(size=self.data.shape) * 0.005, (0, 1)) self.data += np.sin(t * 1760 * np.pi) # 880 Hz self.data = (self.data * 2**10 - 2**9).astype('int16') self.ptr = 0
def main(): canvas = scene.SceneCanvas(keys='interactive', bgcolor='black') view = canvas.central_widget.add_view() view.camera = scene.TurntableCamera(up='z', fov=60) z = np.loadtxt(sys.argv[1]) # in T z *= 10**12 / 10 # rescale (10 pT, 10^-7 G) / 10 text = "Max: %7.2fx10^-6 G" % z.max() put_text(view, (130, 20), text) text = "Min: %7.2fx10^-6 G" % z.min() put_text(view, (130, 45), text) text = "Avg: %7.2fx10^-6 G" % np.average(z) put_text(view, (130, 70), text) z = gaussian_filter(z, (10, 10)) * 10 p1 = scene.visuals.SurfacePlot(z=z, color=(0.1, 0.1, 1, 0.9)) p1.transform = scene.transforms.MatrixTransform() p1.transform.scale([1 / 249., 1 / 249., 1 / 249.]) p1.transform.translate([-0.4, -0.4, 0]) #obsPosition = Vector3d(118.34, 117.69, 119.2) * Mpc put_observer(view, (0, 0, 0), 1. / 20) view.add(p1) put_axes(view.scene) p1._update_data() # cheating. cf = scene.filters.ZColormapFilter('hot', zrange=(z.min(), z.max())) p1.attach(cf) canvas.show()
from vispy import app, scene, visuals from vispy.util.filter import gaussian_filter import numpy as np canvas = scene.SceneCanvas(keys='interactive', title='Isocurve(s) overlayed ' 'over Random Image Example') canvas.size = 800, 600 canvas.show() # Set up a viewbox to display the image with interactive pan/zoom view = canvas.central_widget.add_view() # Create the image img_data = np.empty((200, 100, 3), dtype=np.ubyte) noise = np.random.normal(size=(200, 100), loc=50, scale=150) noise = gaussian_filter(noise, (4, 4, 0)) img_data[:] = noise[..., np.newaxis] image = scene.visuals.Image(img_data, parent=view.scene) # move image behind curves image.transform = visuals.transforms.STTransform(translate=(0, 0, 0.5)) # level and color setup levels = [40, 50, 60] color_lev = [(1, 0, 0, 1), (1, 0.5, 0, 1), (1, 1, 0, 1)] # Create isocurve, make a child of the image to ensure the two are always # aligned. curve = scene.visuals.Isocurve(noise, levels=levels, color_lev=color_lev, parent=view.scene)
import sys import numpy as np from vispy import app, scene from vispy.util.filter import gaussian_filter canvas = scene.SceneCanvas(keys='interactive', bgcolor='w') view = canvas.central_widget.add_view() view.camera = scene.TurntableCamera(up='z', fov=60) # Simple surface plot example # x, y values are not specified, so assumed to be 0:50 z = np.random.normal(size=(250, 250), scale=200) z[100, 100] += 50000 z = gaussian_filter(z, (10, 10)) p1 = scene.visuals.SurfacePlot(z=z, color=(0.3, 0.3, 1, 1)) p1.transform = scene.transforms.MatrixTransform() p1.transform.scale([1 / 249., 1 / 249., 1 / 249.]) p1.transform.translate([-0.5, -0.5, 0]) view.add(p1) # p1._update_data() # cheating. # cf = scene.filters.ZColormapFilter('fire', zrange=(z.max(), z.min())) # p1.attach(cf) xax = scene.Axis(pos=[[-0.5, -0.5], [0.5, -0.5]], tick_direction=(0, -1), font_size=16, axis_color='k',
from vispy.util.filter import gaussian_filter canvas1 = scene.SceneCanvas(keys='interactive', show=True) view1 = canvas1.central_widget.add_view() view1.set_camera('turntable', mode='perspective', up='z', distance=2, azimuth=30., elevation=30.) canvas2 = scene.SceneCanvas(keys='interactive', show=True, shared=canvas1.context) view2 = canvas2.central_widget.add_view() view2.set_camera('panzoom') # todo: fix this after #612 # Simple surface plot example # x, y values are not specified, so assumed to be 0:50 z = gaussian_filter(np.random.normal(size=(50, 50)), (1, 1)) * 10 p1 = scene.visuals.SurfacePlot(z=z, color=(0.5, 0.5, 1, 1), shading='smooth') p1.transform = scene.transforms.AffineTransform() p1.transform.scale([1/49., 1/49., 0.02]) p1.transform.translate([-0.5, -0.5, 0]) view1.add(p1) view2.add(p1) # Add a 3D axis to keep us oriented axis = scene.visuals.XYZAxis(parent=view1.scene) canvas = canvas1 # allow running this example in out test suite if __name__ == '__main__': if sys.flags.interactive == 0:
from vispy import app, scene from vispy.util.filter import gaussian_filter canvas1 = scene.SceneCanvas(keys='interactive', show=True) view1 = canvas1.central_widget.add_view() view1.camera = scene.TurntableCamera(fov=60) canvas2 = scene.SceneCanvas(keys='interactive', show=True, shared=canvas1.context) view2 = canvas2.central_widget.add_view() view2.camera = 'panzoom' # Simple surface plot example # x, y values are not specified, so assumed to be 0:50 z = gaussian_filter(np.random.normal(size=(50, 50)), (1, 1)) * 10 p1 = scene.visuals.SurfacePlot(z=z, color=(0.5, 0.5, 1, 1), shading='smooth') p1.transform = scene.transforms.MatrixTransform() p1.transform.scale([1/49., 1/49., 0.02]) p1.transform.translate([-0.5, -0.5, 0]) view1.add(p1) view2.add(p1) # Add a 3D axis to keep us oriented axis = scene.visuals.XYZAxis(parent=view1.scene) canvas = canvas1 # allow running this example in our test suite if __name__ == '__main__': if sys.flags.interactive == 0:
import sys from vispy import app, scene, visuals from vispy.util.filter import gaussian_filter import numpy as np canvas = scene.SceneCanvas(keys='interactive') canvas.size = 800, 600 canvas.show() # Set up a viewbox to display the image with interactive pan/zoom view = canvas.central_widget.add_view() # Create the image img_data = np.empty((100, 100, 3), dtype=np.ubyte) noise = np.random.normal(size=(100, 100), loc=50, scale=150) noise = gaussian_filter(noise, (4, 4, 0)) img_data[:] = noise[..., np.newaxis] image = scene.visuals.Image(img_data, parent=view.scene) # move image behind curves image.transform = visuals.transforms.STTransform(translate=(0, 0, 0.5)) # Create isocurve, make a child of the image to ensure the two are always # aligned. curve1 = scene.visuals.Isocurve(noise, level=60, color=(1, 1, 0, 1), parent=view.scene) curve2 = scene.visuals.Isocurve(noise, level=50, color=(1, 0.5, 0, 1), parent=view.scene)
canvas._send_hover_events = True # temporary workaround grid = canvas.central_widget.add_grid() vb1 = grid.add_view(row=0, col=0, col_span=2) vb2 = grid.add_view(row=1, col=0) vb3 = grid.add_view(row=1, col=1) # # Top viewbox: Show a plot line containing fine structure with a 1D # magnification transform. # pos = np.empty((100000, 2)) pos[:, 0] = np.arange(100000) pos[:, 1] = np.random.normal(size=100000, loc=50, scale=10) pos[:, 1] = filter.gaussian_filter(pos[:, 1], 20) pos[:, 1] += np.random.normal(size=100000, loc=0, scale=2) pos[:, 1][pos[:, 1] > 55] += 100 pos[:, 1] = filter.gaussian_filter(pos[:, 1], 2) line = visuals.Line(pos, color='white', parent=vb1.scene) line.transform = STTransform(translate=(0, 0, -0.1)) grid1 = visuals.GridLines(parent=vb1.scene) vb1.camera = Magnify1DCamera(mag=4, size_factor=0.6, radius_ratio=0.6) vb1.camera.rect = 0, 30, 100000, 100 # # Bottom-left viewbox: Image with circular magnification lens. # size = (100, 100)
def updatePlot(plot): z = np.random.normal(size=(160, 120), scale=200) z[100, 100] += 50000 z = gaussian_filter(z, (10, 10)) plot.set_data(z=z)
grid = canvas.central_widget.add_grid() vb1 = grid.add_view(row=0, col=0, col_span=2) vb2 = grid.add_view(row=1, col=0) vb3 = grid.add_view(row=1, col=1) # # Top viewbox: Show a plot line containing fine structure with a 1D # magnification transform. # pos = np.empty((100000, 2)) pos[:, 0] = np.arange(100000) pos[:, 1] = np.random.normal(size=100000, loc=50, scale=10) pos[:, 1] = filter.gaussian_filter(pos[:, 1], 20) pos[:, 1] += np.random.normal(size=100000, loc=0, scale=2) pos[:, 1][pos[:, 1] > 55] += 100 pos[:, 1] = filter.gaussian_filter(pos[:, 1], 2) line = visuals.Line(pos, color='white', parent=vb1.scene) line.transform = STTransform(translate=(0, 0, -0.1)) grid1 = visuals.GridLines(parent=vb1.scene) vb1.camera = Magnify1DCamera(mag=4, size_factor=0.6, radius_ratio=0.6) vb1.camera.rect = 0, 30, 100000, 100 # # Bottom-left viewbox: Image with circular magnification lens. # size = (100, 100)
import sys import numpy as np from vispy import app, scene from vispy.util.filter import gaussian_filter canvas = scene.SceneCanvas(keys='interactive', bgcolor='w') view = canvas.central_widget.add_view() view.camera = scene.TurntableCamera(up='z', fov=60) # Simple surface plot example # x, y values are not specified, so assumed to be 0:50 z = np.random.normal(size=(250, 250), scale=200) z[100, 100] += 50000 z = gaussian_filter(z, (10, 10)) p1 = scene.visuals.SurfacePlot(z=z, color=(0.3, 0.3, 1, 1)) p1.transform = scene.transforms.MatrixTransform() p1.transform.scale([1/249., 1/249., 1/249.]) p1.transform.translate([-0.5, -0.5, 0]) view.add(p1) # p1._update_data() # cheating. # cf = scene.filters.ZColormapFilter('fire', zrange=(z.max(), z.min())) # p1.attach(cf) xax = scene.Axis(pos=[[-0.5, -0.5], [0.5, -0.5]], tick_direction=(0, -1), font_size=16, axis_color='k', tick_color='k', text_color='k', parent=view.scene)
grid = canvas.central_widget.add_grid() grid.padding = 0 grid.add_widget(vb1, 0, 0) grid.add_widget(vb2, 0, 1) grid.add_widget(vb3, 1, 0) grid.add_widget(vb4, 1, 1) # panzoom cameras for every viewbox for box in vb: box.camera = 'panzoom' box.camera.aspect = 1.0 # Create random image img_data1 = np.empty((200, 100, 3), dtype=np.ubyte) noise = np.random.normal(size=(200, 100), loc=50, scale=150) noise = gaussian_filter(noise, (4, 4, 0)).astype(np.float32) img_data1[:] = noise[..., np.newaxis] # create 2d array with some function x, y = np.mgrid[0:2*np.pi:201j, 0:2*np.pi:101j] myfunc = np.cos(2*x[:-1, :-1]) + np.sin(2*y[:-1, :-1]) myfunc = myfunc.astype(np.float32) # add image to viewbox1 image1 = scene.visuals.Image(noise, parent=vb1.scene, cmap='cubehelix') # move image behind curves image1.transform = STTransform(translate=(0, 0, 0.5)) vb1.camera.set_range() # add image to viewbox2 image2 = scene.visuals.Image(myfunc, parent=vb2.scene, cmap='cubehelix')