def surf_demo2(**kwargs): from mpl_toolkits.mplot3d import Axes3D import numpy as np from ifigure.interactive import surf, threed, figure, isec, nsec figure(gl=True) nsec(3) isec(0) threed('on') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) surf(x, y, z, cz=False, facecolor='b', edgecolor='k') isec(1) threed('on') surf(x, y, z, cstride=4, cz=True, edgecolor='k') isec(2) threed('on') surf(x, y, z, cz=True, cdata=y, edgecolor=None)
def trisurf3d_demo(**kwargs): from matplotlib import cm import numpy as np from ifigure.interactive import figure, threed, trisurf, nsec, isec, lighting # preparing the data, the same as mplot3d demo n_angles = 36 n_radii = 8 radii = np.linspace(0.125, 1.0, n_radii) angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) x = np.append(0, (radii * np.cos(angles)).flatten()) y = np.append(0, (radii * np.sin(angles)).flatten()) z = np.sin(-x * y) v = figure() nsec(3) isec(0) threed('on') trisurf(x, y, z, cmap=cm.jet, linewidth=0.2, cz=True) isec(1) threed('on') trisurf(x, y, z, linewidth=0.2, color='b') lighting(light=0.5, ambient=0.5) isec(2) threed('on') trisurf(x, y, z * 0, cmap=cm.jet, linewidth=0.2, cz=True, cdata=z, edgecolor=None)
def quiver_demo(**kwargs): ''' quiver_demo(length = 1.0, normalize = True, facecolor = 'b', edgecolor = None, arrow_length_ratio = 0.3, shaftsize = 0.01, headsize = 0.01) ''' from ifigure.interactive import quiver, threed, figure, lighting, view, isec, nsec x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.8)) u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z) v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z) w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) figure() nsec(2) isec(0) threed('on') lighting(light=0.5, ambient=0.7) view('noclip') quiver(x, y, z, u, v, w, length=0.3, facecolor='b') isec(1) threed('on') lighting(light=0.5, ambient=0.7) view('noclip') quiver(x, y, z, u, v, w, cz=True, cdata=y, length=0.3)
def surf_demo2(**kwargs): from mpl_toolkits.mplot3d import Axes3D import numpy as np from ifigure.interactive import surf, threed, figure, isec, nsec figure(gl = True) nsec(3) isec(0) threed('on') u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 10 * np.outer(np.cos(u), np.sin(v)) y = 10 * np.outer(np.sin(u), np.sin(v)) z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) surf(x, y, z, cz = False, facecolor='b', edgecolor = 'k') isec(1) threed('on') surf(x, y, z, cstride=4, cz = True, edgecolor = 'k') isec(2) threed('on') surf(x, y, z, cz = True, cdata = y, edgecolor = None)
def trisurf3d_demo(**kwargs): from matplotlib import cm import numpy as np from ifigure.interactive import figure, threed, trisurf , nsec, isec, lighting # preparing the data, the same as mplot3d demo n_angles = 36 n_radii = 8 radii = np.linspace(0.125, 1.0, n_radii) angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1) x = np.append(0, (radii*np.cos(angles)).flatten()) y = np.append(0, (radii*np.sin(angles)).flatten()) z = np.sin(-x*y) v = figure() nsec(3) isec(0) threed('on') trisurf(x, y, z, cmap=cm.jet, linewidth=0.2, cz = True) isec(1) threed('on') trisurf(x, y, z, linewidth=0.2, color='b') lighting(light = 0.5, ambient = 0.5) isec(2) threed('on') trisurf(x, y, z*0, cmap=cm.jet, linewidth=0.2, cz = True, cdata = z, edgecolor = None)
def quiver_demo(**kwargs): ''' quiver_demo(length = 1.0, normalize = True, facecolor = 'b', edgecolor = None, arrow_length_ratio = 0.3, shaftsize = 0.01, headsize = 0.01) ''' from ifigure.interactive import quiver, threed, figure, lighting, view, isec, nsec x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.2), np.arange(-0.8, 1, 0.8)) u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z) v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z) w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) * np.sin(np.pi * z)) figure() nsec(2) isec(0) threed('on') lighting(light = 0.5, ambient = 0.7) view('noclip') quiver(x, y, z, u, v, w, length = 0.3, facecolor = 'b') isec(1) threed('on') lighting(light = 0.5, ambient = 0.7) view('noclip') quiver(x, y, z, u, v, w, cz = True, cdata = y, length = 0.3)
def specgram_demo(): ''' the demo in matplotlib. But calls interactive.specgram ''' from pylab import arange, sin, where, logical_and, randn, pi dt = 0.0005 t = arange(0.0, 20.0, dt) s1 = sin(2*pi*100*t) s2 = 2*sin(2*pi*400*t) # create a transient "chirp" mask = where(logical_and(t>10, t<12), 1.0, 0.0) s2 = s2 * mask # add some noise into the mix nse = 0.01*randn(len(t)) x = s1 + s2 + nse # the signal NFFT = 1024 # the length of the windowing segments Fs = int(1.0/dt) # the sampling frequency from ifigure.interactive import figure, specgram, nsec, plot, isec, clog, hold figure() hold(True) nsec(2) isec(0) plot(t, x) isec(1) specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) clog()
def spec_demo(): ''' the demo in matplotlib. But calls interactive.specgram ''' from pylab import arange, sin, where, logical_and, randn, pi dt = 0.0005 t = arange(0.0, 20.0, dt) s1 = sin(2 * pi * 100 * t) s2 = 2 * sin(2 * pi * 400 * t) # create a transient "chirp" mask = where(logical_and(t > 10, t < 12), 1.0, 0.0) s2 = s2 * mask # add some noise into the mix nse = 0.01 * randn(len(t)) x = s1 + s2 + nse # the signal NFFT = 1024 # the length of the windowing segments Fs = int(1.0 / dt) # the sampling frequency from ifigure.interactive import figure, spec, nsec, plot, isec, clog, hold figure() hold(True) nsec(2) isec(0) plot(t, x) isec(1) spec(t, x, NFFT=NFFT, noverlap=900) clog()
def onSlice(self, event): from ifigure.interactive import figure, plot, nsec, isec, update, title, xlabel, ylabel if event.mpl_xydata[0] is None: return for a in self._artists: axes = a.axes if axes is None: return data1, data2 = self.get_slice(event.mpl_xy[0], event.mpl_xy[1], a) if data1 is None: continue if data2 is None: continue figure() nsec(2) ou = update() isec(0) plot(data1[0], data1[1]) title('y slice : y = '+str(event.mpl_xydata[1])) xlabel('x') isec(1) plot(data2[0], data2[1]) title('x slice : x = '+str(event.mpl_xydata[0])) xlabel('y') update(ou)
def hist_demo(**kwargs): from ifigure.interactive import hist, nsec, isec x1 = np.random.random_sample(4000) x2 = np.random.random_sample(400)*3 hist(x1) nsec(3) isec(1) hist([x1, x2]) isec(2) hist(x1.reshape(1000,4))
def hist_demo(**kwargs): from ifigure.interactive import hist, nsec, isec x1 = np.random.random_sample(4000) x2 = np.random.random_sample(400) * 3 hist(x1) nsec(3) isec(1) hist([x1, x2]) isec(2) hist(x1.reshape(1000, 4))
def solid_demo(**kwargs): ''' solid_demo2(cz = True, linewidths = 1.0, edgecolor='red') solid_demo2(facecolor='b', linewidths = 1.0, edgecolor='red') ''' from ifigure.interactive import solid, figure, threed, isec, nsec, lighting import ifigure, os # preparing the data, the same as mplot3d demo theta = np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) r = np.linspace(0.01, 4.0, endpoint=True, num=50) # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple THETA, R = np.meshgrid(theta, r) X = R * np.cos(THETA) Y = R * np.sin(THETA) Z = np.exp(-R * R) import matplotlib.tri as mtri tri = mtri.Triangulation(X.flatten(), Y.flatten()) # Triangulate parameter space to determine the triangles if 'cz' in kwargs and kwargs['cz']: v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten())) kwargs['cdata'] = 5 * Z.flatten()[tri.triangles] kwargs['cdata'] = 5 * Z.flatten() kwargs['cz'] = True # or # v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], 5 * Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten(), 5 * Z.flatten())) elif 'twod' in kwargs and kwargs['twod']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles]), ) v = np.vstack(( tri.x, tri.y, )) kwargs.pop('twod') kwargs['zvalue'] = 1.0 else: v = np.dstack(( tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], )) v = np.vstack((tri.x, tri.y, Z.flatten())) idxset = tri.triangles v = v.transpose() print v.shape, idxset.shape viewer = figure() nsec(3) isec(0) threed('on') solid(v, idxset, edgecolor='k', facecolor='b') lighting(light=0.5, ambient=0.5) isec(1) threed('on') solid(v, idxset, cz=True) lighting(light=0.5, ambient=0.5) isec(2) threed('on') solid(v, idxset, cz=True, cdata=v[..., 0], shade='linear') lighting(light=0.5, ambient=0.5)
def solid_demo(**kwargs): ''' solid_demo2(cz = True, linewidths = 1.0, edgecolor='red') solid_demo2(facecolor='b', linewidths = 1.0, edgecolor='red') ''' from ifigure.interactive import solid, figure, threed, isec, nsec, lighting import ifigure, os # preparing the data, the same as mplot3d demo theta = np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) r = np.linspace(0.01, 4.0, endpoint=True, num=50) # This is the Mobius mapping, taking a u, v pair and returning an x, y, z # triple THETA, R = np.meshgrid(theta, r) X = R*np.cos(THETA) Y = R*np.sin(THETA) Z = np.exp(- R*R) import matplotlib.tri as mtri tri = mtri.Triangulation(X.flatten(), Y.flatten()) # Triangulate parameter space to determine the triangles if 'cz' in kwargs and kwargs['cz']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten())) kwargs['cdata'] = 5*Z.flatten()[tri.triangles] kwargs['cdata'] = 5*Z.flatten() kwargs['cz'] = True # or # v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles], 5 * Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten(), 5*Z.flatten())) elif 'twod' in kwargs and kwargs['twod']: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles]),) v = np.vstack((tri.x, tri.y, )) kwargs.pop('twod') kwargs['zvalue'] = 1.0 else: v = np.dstack((tri.x[tri.triangles], tri.y[tri.triangles], Z.flatten()[tri.triangles],)) v = np.vstack((tri.x, tri.y, Z.flatten())) idxset=tri.triangles v = v.transpose() print v.shape, idxset.shape viewer = figure() nsec(3) isec(0) threed('on') solid(v, idxset, edgecolor = 'k', facecolor = 'b') lighting(light = 0.5, ambient = 0.5) isec(1) threed('on') solid(v, idxset, cz = True) lighting(light = 0.5, ambient = 0.5) isec(2) threed('on') solid(v, idxset, cz = True, cdata = v[...,0], shade='linear') lighting(light = 0.5, ambient = 0.5)