def test_barchart(self): s = np.random.random((10, 10)) x, y = np.indices(s.shape) bar1 = mlab.barchart(x, y, s) bar2 = mlab.barchart(s) bar3 = mlab.barchart(s, auto_scale=False) # Check that auto scaling worked well in the different # configurations for bar in bar1, bar2, bar3: self.assertEqual(bar.glyph.glyph_source.glyph_source.y_length, 0.9)
def test_barchart(self): """Test the barchart function.""" s = np.abs(np.random.random((3,3))) b = mlab.barchart(s) self.assertEqual(b.glyph.glyph.scale_mode, 'scale_by_vector_components') s += 1 b.mlab_source.update() self.assertEqual(b.glyph.glyph.scale_mode, 'scale_by_vector_components')
def test_barchart(self): """Test the barchart function.""" s = np.abs(np.random.random((3, 3))) b = mlab.barchart(s) self.assertEqual(b.glyph.glyph.scale_mode, 'scale_by_vector_components') s += 1 b.mlab_source.update() self.assertEqual(b.glyph.glyph.scale_mode, 'scale_by_vector_components')
def plot_3d_spectrum_mayavi(fs, fignum=None, vmin=None, vmax=None, pop_ids=None): """ Logarithmic heatmap of single 3d FS. This method relies on MayaVi2's mlab interface. See http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html . To edit plot properties, click leftmost icon in the toolbar. If you get an ImportError upon calling this function, it is likely that you don't have mayavi installed. fs: FS to plot vmin: Values in fs below vmin are masked in plot. vmax: Values in fs above vmax saturate the color spectrum. fignum: Figure number to plot into. If None, a new figure will be created. Note that these are MayaVi figures, which are separate from matplotlib figures. pop_ids: If not None, override pop_ids stored in Spectrum. """ from enthought.mayavi import mlab fig = mlab.figure(fignum, bgcolor=(1,1,1)) mlab.clf(fig) if vmin is None: vmin = fs.min() if vmax is None: vmax = fs.max() # Which entries should I plot? toplot = numpy.logical_not(fs.mask) toplot = numpy.logical_and(toplot, fs.data >= vmin) # For the color mapping normalized = (numpy.log(fs)-numpy.log(vmin))\ /(numpy.log(vmax)-numpy.log(vmin)) normalized = numpy.minimum(normalized, 1) xs,ys,zs = numpy.indices(fs.shape) flat_xs = xs.flatten() flat_ys = ys.flatten() flat_zs = zs.flatten() flat_toplot = toplot.flatten() mlab.barchart(flat_xs[flat_toplot], flat_ys[flat_toplot], flat_zs[flat_toplot], normalized.flatten()[flat_toplot], colormap='hsv', scale_mode='none', lateral_scale=1, figure=fig) if pop_ids is None: if fs.pop_ids is not None: pop_ids = fs.pop_ids else: pop_ids = ['pop0','pop1','pop2'] a = mlab.axes(xlabel=pop_ids[0],ylabel=pop_ids[1],zlabel=pop_ids[2], figure=fig, color=(0,0,0)) a.axes.label_format = "" a.title_text_property.color = (0,0,0) mlab.text3d(fs.sample_sizes[0],fs.sample_sizes[1],fs.sample_sizes[2]+1, '(%i,%i,%i)'%tuple(fs.sample_sizes), scale=0.75, figure=fig, color=(0,0,0)) mlab.view(azimuth=-40, elevation=65, distance='auto', focalpoint='auto') mlab.show()
yticks(()) image2 = array(image2) subplot(1, 2, 2) pcolor(image2, cmap=cm.jet, vmin=-1, vmax=1, shading='faceted') xticks(()) yticks(()) savefig('laplacien.eps') show() from enthought.mayavi import mlab mlab.figure(1, size=(720, 300)) mlab.clf() import numpy as np x_, y_ = np.indices(image.shape) mlab.barchart(x_, y_ - 3, 2 * image, vmin=-1, vmax=1) mlab.barchart(x_, y_ + 3, 2 * image2, vmin=-1, vmax=1) mlab.view(0, 63, 8.5, (3, 2, 1)) mlab.savefig('laplacien.jpg') import os os.system('mogrify -trim laplacien.jpg') from numpy import zeros image = zeros((size, size)) image[size / 2, size / 2] = 1 def laplacien_numpy(): image[1:-1, 1:-1] = (image[:-2, 1:-1] - image[2:, 1:-1] + image[1:-1, :-2] - image[1:-1, 2:]) * 0.25
regions = lulu.decompose(img) value_maxes = [] height = 0 for area in sorted(regions.keys()): pulses = regions[area] if len(pulses) == 0 or area < 280 or area > 300: continue values = [crh.get_value(p) for p in pulses] height_diff = max(values) - min(values) value_maxes.append(height_diff) centre = height + height_diff / 2.0 pulse_values = np.zeros_like(img) for p in pulses: crh.set_array(pulse_values, p, crh.get_value(p)) y, x = np.where(pulse_values) s = pulse_values[y, x] mlab.barchart(x, y, [height + centre] * len(s), s, opacity=1.0, scale_factor=1.5) height += height_diff + 0.5 scene = mlab.get_engine().scenes[0] scene.scene.parallel_projection = True mlab.show()
yticks(()) image2 = array(image2) subplot(1, 2, 2) pcolor(image2, cmap=cm.jet, vmin=-1, vmax=1, shading='faceted') xticks(()) yticks(()) savefig('laplacien.eps') show() from enthought.mayavi import mlab mlab.figure(1, size=(720, 300)) mlab.clf() import numpy as np x_, y_ = np.indices(image.shape) mlab.barchart(x_, y_ - 3, 2*image, vmin=-1, vmax=1) mlab.barchart(x_, y_ + 3, 2*image2, vmin=-1, vmax=1) mlab.view(0, 63, 8.5, (3, 2, 1)) mlab.savefig('laplacien.jpg') import os os.system('mogrify -trim laplacien.jpg') from numpy import zeros image = zeros((size, size)) image[size/2, size/2] = 1 def laplacien_numpy(): image[1:-1, 1:-1] = (image[:-2, 1:-1] - image[2:, 1:-1] + image[1:-1, :-2] - image[1:-1, 2:])*0.25
height = 0 for area in sorted(regions.keys()): pulses = regions[area] if len(pulses) == 0 or area < 280 or area > 300: continue values = [crh.get_value(p) for p in pulses] height_diff = max(values) - min(values) value_maxes.append(height_diff) centre = height + height_diff / 2.0 pulse_values = np.zeros_like(img) for p in pulses: crh.set_array(pulse_values, p, crh.get_value(p)) y, x = np.where(pulse_values) s = pulse_values[y, x] mlab.barchart(x, y, [height + centre] * len(s), s, opacity=1.0, scale_factor=1.5) height += height_diff + 0.5 scene = mlab.get_engine().scenes[0] scene.scene.parallel_projection = True mlab.show()