本文整理汇总了Python中mayavi.mlab.colorbar函数的典型用法代码示例。如果您正苦于以下问题:Python colorbar函数的具体用法?Python colorbar怎么用?Python colorbar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了colorbar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_mlab
def do_mlab():
f = open(sys.argv[1]+"/index.list","r")
lines = f.readlines()
calls = []
lc = None
for i,line in enumerate(lines):
calls.append( (i, sys.argv[1]+line[:-1])) #,region=[0,10000,0,30,8,13])
lc = sys.argv[1]+line[:-1]
print calls
ppservers = ()
job_server = pp.Server(ppservers=ppservers, ncpus = 10)
print "Starting pp with", job_server.get_ncpus(), "workers"
# The following submits 8 jobs and then retrieves the results
jobs = [ job_server.submit(readdata,(data[1],), (mfilter,), ("mmdlab","mmdlab.datareader")) for data in calls];
size = int(1920), int(1080)
fig = mlab.figure('Viz', size=size,bgcolor=(0,0,0))
fig.scene.anti_aliasing_frames = 0
import time
gas = []
for i,job in enumerate(jobs):
(metal,g) = job()
gas.append(g)
print "Job",i,"done"
traj = get_traj(gas)
parts_no = [8144152,8156221, 8131715, 8146196, 8134778, 8141532, 8132951, 8145946, 8133361,
8129611, 8137788, 8140157, 8146085,]
lm,lg = readfile_metgas_bin(lc, pfilter=mfilter, parts_at_once=10000)
for p in parts_no:
val = traj[p]
ppl = mlab.plot3d(val["x"], val["y"], val["z"], val["t"], tube_radius=0.025, colormap='cool');
mlab.colorbar(ppl)
#for g in gas:
# mlab.points3d(g.x[numpy.where(g.n == p)],g.y[numpy.where(g.n == p)],g.z[numpy.where(g.n == p)],scale_factor=lm.d, colormap='cool')
# mlab.text(color=(1,0,0),width=0.06,x = g.x[numpy.where(g.n == p)][0],y= g.y[numpy.where(g.n == p)][0],z = g.z[numpy.where(g.n == p)][0],text = str(g.t[numpy.where(g.n == p)][0]))
#mlab.points3d(lg.x, lg.y, lg.z, lg.t, scale_mode="none",scale_factor=lg.d, colormap="cool")
mscat = mlab.pipeline.scalar_scatter(lm.x, lm.y, lm.z)
mgauss = mlab.pipeline.gaussian_splatter(mscat)
mlab.pipeline.iso_surface(mgauss,colormap="black-white",contours=[0.9999,],opacity = 1)
#mlab.points3d(lm.x, lm.y, lm.z, lm.t, scale_mode="none",scale_factor=lm.d, colormap="copper")
#for val in traj.values():
#
#print "Drawing metal"
#metp = mlab.points3d(metal.x,metal.y,metal.z,metal.v,scale_mode="none",scale_factor=metal.d, colormap="copper",mode = "point",mask_points = 100)
#print "Drawing gas"
#gasp = mlab.points3d(gas.x,gas.y,gas.z,gas.v,scale_mode="none",scale_factor=gas.d,colormap="cool")
#print "saving to ./vid/{num:02d}.png".format(num=i)
#mlab.savefig("./vid/{num:02d}.png".format(num=i))
#mlab.clf()
mlab.show()
示例2: plotvtk3D
def plotvtk3D(self):
"""
3D plot using the vtk libraries
"""
from tvtk.api import tvtk
from mayavi import mlab
# Plot the data on a 3D grid
xy = np.column_stack((self.grd.xp,self.grd.yp))
dvp = self.F(xy)
vertexag = 50.0
points = np.column_stack((self.grd.xp,self.grd.yp,dvp*vertexag))
tri_type = tvtk.Triangle().cell_type
#tet_type = tvtk.Tetra().cell_type
ug = tvtk.UnstructuredGrid(points=points)
ug.set_cells(tri_type, self.grd.cells)
ug.cell_data.scalars = self.grd.dv
ug.cell_data.scalars.name = 'depths'
f=mlab.gcf()
f.scene.background = (0.,0.,0.)
d = mlab.pipeline.add_dataset(ug)
h=mlab.pipeline.surface(d,colormap='gist_earth')
mlab.colorbar(object=h,orientation='vertical')
mlab.view(0,0)
outfile = self.suntanspath+'/depths.png'
f.scene.save(outfile)
print 'Figure saved to %s.'%outfile
示例3: xmas_balls
def xmas_balls(connectivity, node_data=None, edge_data=False):
"""
Plots coloured balls at the region centres of connectivity, colour and
size is determined by a vector of length number of regions (node_data).
Optional: adds the connections between pair of nodes.
"""
centres = connectivity.centres
edges = numpy.array(numpy.nonzero(connectivity.weights))
edges = numpy.array([(start, stop) for (start, stop) in edges.T if start != stop])
if node_data is not None:
data_scale = 13.0 / node_data.max()
pts = mlab.points3d(centres[:, 0], centres[:, 1], centres[:, 2],
node_data, transparent=True,
scale_factor=data_scale,
colormap='Blues')
mlab.colorbar(orientation="vertical")
else:
#NOTE: the magic numbers are used to align region centers and surface representation.
#Do not ask ...
pts = mlab.points3d(centres[:, 0] * 1.13, centres[:, 1] * 1.13 + 15, centres[:, 2] - 25)
if edge_data:
pts.mlab_source.dataset.lines = edges
tube = mlab.pipeline.tube(pts, tube_radius=0.5)
mlab.pipeline.surface(tube, colormap='binary', opacity=0.142)
示例4: action
def action(u, x, xv, y, yv, t, n):
#print 'action, t=',t,'\nu=',u, '\Nx=',x, '\Ny=', y
if plot == 1:
mesh(xv, yv, u, title='t=%g' %t[n])
time.sleep(0.2) # pause between frames
elif plot == 2:
# mayavi plotting
mlab.clf()
extent1 = (0, 20, 0, 20,-2, 2)
s = mlab.surf(x , y, u, colormap='Blues', warp_scale=5,extent=extent1)
mlab.axes(s, color=(.7, .7, .7), extent=extent1,
ranges=(0, 10, 0, 10, -1, 1), xlabel='', ylabel='',
zlabel='',
x_axis_visibility=False, z_axis_visibility=False)
mlab.outline(s, color=(0.7, .7, .7), extent=extent1)
mlab.text(2, -2.5, '', z=-4, width=0.1)
mlab.colorbar(object=None, title=None, orientation='horizontal', nb_labels=None, nb_colors=None, label_fmt=None)
mlab.title('test 1D t=%g' % t[n])
mlab.view(142, -72, 50)
f = mlab.gcf()
camera = f.scene.camera
camera.yaw(0)
if plot > 0:
path = 'Figures_wave2D'
time.sleep(0) # pause between frames
if save_plot and plot != 2:
filename = '%s/%08d.png' % (path, n)
savefig(filename) # time consuming!
elif save_plot and plot == 2:
filename = '%s/%08d.png' % (path,n)
mlab.savefig(filename) # time consuming!
示例5: generate_plots_3d
def generate_plots_3d(self):
self.ax = mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(800, 600))
self.clf = mlab.clf()
minS, maxS = maxint, 0
contour_plots = []
for cond in self.conductors.itervalues():
minS, maxS, face_data = self.generate_plot_data_for_faces_3d(cond, minS, maxS)
for (x, y, z, s) in face_data:
if isinstance(cond, conductor_type_3d['Unstructured']):
pts = mlab.points3d(x, y, z, s, scale_mode='none', scale_factor=0.002)
mesh = mlab.pipeline.delaunay3d(pts)
contour_plots.append(mlab.pipeline.surface(mesh, colormap='viridis'))
else:
if np.min(s) < 0.0:
contour_plots.append(mlab.mesh(x, y, z, color=(0, 0, 0), colormap='viridis'))
else:
contour_plots.append(mlab.mesh(x, y, z, scalars=s, colormap='viridis'))
for cp in contour_plots:
cp.module_manager.scalar_lut_manager.trait_set(default_data_range=[minS * 0.95, maxS * 1.05])
mlab.draw()
mlab.colorbar(object=contour_plots[0], orientation='vertical')
mlab.show()
示例6: draw
def draw(self,**kwargs):
x = np.linspace(self._base_square_x[0],
self._base_square_x[1],self._Nl)
y = np.linspace(self._base_square_y[0],
self._base_square_y[1],self._Nw)
x,y = np.meshgrid(x,y)
z = 0.0*x
for trans in self._transforms:
p = np.concatenate((x[:,:,None],
y[:,:,None],
z[:,:,None]),
axis=-1)
p = trans(p)
pflat = np.reshape(p,(-1,3))
c = self._f(pflat,*self._f_args,**self._f_kwargs)
c = np.reshape(c,np.shape(p)[:-1])
if self._clim is None:
self._clim = (np.min(c),np.max(c))
m = mlab.mesh(p[:,:,0],p[:,:,1],p[:,:,2],
scalars=c,
vmin=self._clim[0],
vmax=self._clim[1],**kwargs)
m.module_manager.scalar_lut_manager.lut.table = self._rgba
mlab.colorbar()
mlab.draw()
if self._plots is None:
self._plots = (m,trans),
else:
self._plots += (m,trans),
return [i[0] for i in self._plots]
示例7: showDsweep
def showDsweep():
k_s_sweep = [10**(x-5) for x in range(10)]
sl_div_diam_sweep = [5.0*(x+1)/1000 for x in range(20)]
vol_ratio_sweep = [5.0*(x+1)/100 for x in range(10)]
Dmsd = numpy.load(data_dir + "/D_numpy.npy")
kDa = 1.660538921e-30;
mass = 40.0*kDa;
viscosity = 8.9e-4;
diameter = 5e-9;
T = 300.0;
Dbase = k_b*T/(3.0*numpy.pi*viscosity*diameter);
Dmsd = Dmsd/Dbase
mlab.figure(1, size=(800, 800), fgcolor=(1, 1, 1),
bgcolor=(0.5, 0.5, 0.5))
mlab.clf()
contours = numpy.arange(0.01,2,0.2).tolist()
obj = mlab.contour3d(Dmsd,contours=contours,transparent=True,vmin=contours[0],vmax=contours[-1])
outline = mlab.outline(color=(.7, .7, .7),extent=(0,10,0,20,0,10))
axes = mlab.axes(outline, color=(.7, .7, .7),
nb_labels = 5,
ranges=(k_s_sweep[0], k_s_sweep[-1], sl_div_diam_sweep[0], sl_div_diam_sweep[-1], vol_ratio_sweep[0], vol_ratio_sweep[-1]),
xlabel='spring stiffness',
ylabel='step length',
zlabel='volume ratio')
mlab.colorbar(obj,title='D',nb_labels=5)
mlab.show()
示例8: surface_timeseries
def surface_timeseries(surface, data, step=1):
"""
"""
fig = mlab.figure(figure="surface_timeseries", fgcolor=(0.5, 0.5, 0.5))
#Plot an initial surface and colourbar #TODO: Change to use plot_surface function, see below.
surf_mesh = mlab.triangular_mesh(surface.vertices[:, 0],
surface.vertices[:, 1],
surface.vertices[:, 2],
surface.triangles,
scalars=data[0, :],
vmin=data.min(), vmax=data.max(),
figure=fig)
mlab.colorbar(object=surf_mesh, orientation="vertical")
#Handle for the surface object and figure
surf = surf_mesh.mlab_source
#Time #TODO: Make actual time rather than points, where/if possible.
tpts = data.shape[0]
time_step = mlab.text(0.85, 0.125, ("0 of %s" % str(tpts)),
width=0.0625, color=(1, 1, 1), figure=fig,
name="counter")
#Movie
k = 0
while 1:
if abs(k) >= tpts:
k = 0
surf.set(scalars=data[k, :])
time_step.set(text=("%s of %s" % (str(k), str(tpts))))
k += step
yield
mlab.show(stop=True)
示例9: plot_trajectory
def plot_trajectory(perf_data, stimset, stim_class, symbols, post_stim_time=1):
net = perf_data.net
net.noise_std = 0.0
mlab.figure(bgcolor=(0.5, 0.5, 0.5), fgcolor=(0.0, 0.0, 0.0))
for symbol in symbols:
stim_md5 = stimset.symbol_to_md5[symbol][0]
stim = stimset.all_stims[stim_md5]
net_sims = run_sim(net, {stim_md5:stim},
burn_time=100,
pre_stim_time = 1,
post_stim_time=max(25, post_stim_time),
num_trials=1)
sim = net_sims[stim_md5]
avg_resp = sim.responses[0, :, :].squeeze()
stim_start = 0
record_time = len(stim) + 1
stim_end = len(stim) + post_stim_time
stimsym = stimset.md5_to_symbol[stim_md5]
#stim_str = '%s:%s (%0.2f)' % (stimsym, ''.join(['%d' % s for s in stim]), perf_data.logit_perf)
stim_str = '%s:%s' % (stimsym, ''.join(['%d' % s for s in stim]))
t = np.arange(0, stim_end)
traj = mlab.plot3d(avg_resp[0:stim_end, 0], avg_resp[0:stim_end, 1], avg_resp[0:stim_end, 2], t,
colormap='hot', tube_radius=None)
#mlab.points3d(avg_resp[stim_start, 0], avg_resp[stim_start, 1], avg_resp[stim_start, 2], scale_factor=0.300)
mlab.points3d(avg_resp[record_time-1, 0], avg_resp[record_time-1, 1], avg_resp[record_time-1, 2], scale_factor=0.900)
mlab.colorbar()
if len(symbols) == 1:
mlab.title(stim_str)
示例10: plot_surface
def plot_surface(surf_name, data_orig, hemi='rh', cmin=None, cmax=None, colorbar=True, smooth=5):
''' Plots data in a 3D brain surface using the current Mayavi's mlab window. surf_name is a string with the name of the surface, data is a vector of the same length of the number of points in the surface. Function performs smoothing by default, and set the color of the brain to gray by default for points we don't have data. '''
surf = loadmat('/Users/sudregp/Documents/surfaces/IMAGING_TOOLS/' + surf_name + '.mat')
nbr = surf['nbr_' + hemi].astype(int)
# making sure we don't change the original data
data = data_orig.copy()
num_voxels = len(data)
# smoothing data to neighboring voxels with zero value. Algorithm described in MNE-manual-2.7, page 208/356.
for p in range(smooth):
print 'Smoothing step ' + str(p + 1) + '/' + str(smooth)
S = np.zeros([num_voxels, num_voxels])
for j in range(num_voxels):
my_neighbors = nbr[j, :] - 1
# remove entries that are -1
my_neighbors = np.delete(my_neighbors, np.nonzero(my_neighbors == -1))
# number of immediate neighbors with non zero values
Nj = np.sum(data[my_neighbors] != 0)
if Nj > 0:
pdb.set_trace()
S[j, my_neighbors] = 1 / float(Nj)
data = np.dot(S, data)
pdb.set_trace()
# replacing all values that are still 0 by something that is not in the data range.
data[data == 0] = np.inf
if cmin is None:
cmin = np.min(data)
if cmax is None:
# check whether we have empty points in the brain. If we do, it has Inf value. If not, the max is the actual maximum of the data
if len(np.nonzero(np.isinf(data) == True)[0]) == 0:
cmax = np.max(data)
add_grey = False
else:
cmax = np.unique(np.sort(data))[-2]
add_grey = True
else:
# if cmax was specified, let the person deal with it
add_grey = False
surf = mlab.triangular_mesh(surf['coord_' + hemi][0, :], surf['coord_' + hemi][1, :], surf['coord_' + hemi][2, :], surf['tri_' + hemi] - 1, scalars=data, vmax=cmax, vmin=cmin)
if add_grey:
# add grey color to scale, and make everything that's infinity that color
surf.module_manager.scalar_lut_manager.number_of_colors += 1
lut = surf.module_manager.scalar_lut_manager.lut.table.to_array()
grey_row = [192, 192, 192, 255]
# sets the max value in the data range to be gray
lut = np.vstack((lut, grey_row))
surf.module_manager.scalar_lut_manager.lut.table = lut
fig = mlab.gcf()
# fig.on_mouse_pick(picker_callback)
mlab.colorbar()
return surf
示例11: draw_cloud
def draw_cloud(self, points3d, scale=1):
scale = self.scale * scale
mlab.points3d(points3d[:, 0], points3d[:, 1],
points3d[:, 2], points3d[:, 2],
colormap='jet', opacity=0.75, scale_factor=scale)
mlab.outline()
mlab.colorbar(title='Planar disparity (mm)')
mlab.axes()
示例12: plot_u
def plot_u(u, x, xv, y, yv, t, n):
"""User action function for plotting."""
if t[n] == 0:
time.sleep(2)
if plot_method == 1:
# Works well with Gnuplot backend, not with Matplotlib
st.mesh(x, y, u, title='t=%g' % t[n], zlim=[-1,1],
caxis=[-1,1])
elif plot_method == 2:
# Works well with Gnuplot backend, not with Matplotlib
st.surfc(xv, yv, u, title='t=%g' % t[n], zlim=[-1, 1],
colorbar=True, colormap=st.hot(), caxis=[-1,1],
shading='flat')
elif plot_method == 3:
print 'Experimental 3D matplotlib...under development...'
# Probably too slow
#plt.clf()
ax = fig.add_subplot(111, projection='3d')
u_surf = ax.plot_surface(xv, yv, u, alpha=0.3)
#ax.contourf(xv, yv, u, zdir='z', offset=-100, cmap=cm.coolwarm)
#ax.set_zlim(-1, 1)
# Remove old surface before drawing
if u_surf is not None:
ax.collections.remove(u_surf)
plt.draw()
time.sleep(1)
elif plot_method == 4:
# Mayavi visualization
mlab.clf()
extent1 = (0, 20, 0, 20,-2, 2)
s = mlab.surf(x , y, u,
colormap='Blues',
warp_scale=5,extent=extent1)
mlab.axes(s, color=(.7, .7, .7), extent=extent1,
ranges=(0, 10, 0, 10, -1, 1),
xlabel='', ylabel='', zlabel='',
x_axis_visibility=False,
z_axis_visibility=False)
mlab.outline(s, color=(0.7, .7, .7), extent=extent1)
mlab.text(6, -2.5, '', z=-4, width=0.14)
mlab.colorbar(object=None, title=None,
orientation='horizontal',
nb_labels=None, nb_colors=None,
label_fmt=None)
mlab.title('Gaussian t=%g' % t[n])
mlab.view(142, -72, 50)
f = mlab.gcf()
camera = f.scene.camera
camera.yaw(0)
if plot_method > 0:
time.sleep(0) # pause between frames
if save_plot:
filename = 'tmp_%04d.png' % n
if plot_method == 4:
mlab.savefig(filename) # time consuming!
elif plot_method in (1,2):
st.savefig(filename) # time consuming!
示例13: surfacePlot
def surfacePlot(
Hmap,
nrows,
ncols,
xyspacing,
zscale,
name,
hRange,
file_path,
lutfromfile,
lut,
lut_file_path,
colorbar_on,
save,
show,
):
# Create a grid of the x and y coordinates corresponding to each pixel in the height matrix
x, y = np.mgrid[0 : ncols * xyspacing : xyspacing, 0 : nrows * xyspacing : xyspacing]
# Create a new figure
mlab.figure(size=(1000, 1000))
# Set the background color if desired
# bgcolor=(0.16, 0.28, 0.46)
# Create the surface plot of the reconstructed data
plot = mlab.surf(x, y, Hmap, warp_scale=zscale, vmin=hRange[0], vmax=hRange[1], colormap=lut)
# Import the LUT from a file if necessary
if lutfromfile:
plot.module_manager.scalar_lut_manager.load_lut_from_file(lut_file_path)
# Draw the figure with the new LUT if necessary
mlab.draw()
# Zoom in to fill the entire window
f = mlab.gcf()
f.scene.camera.zoom(1.05)
# Change the view to a top-down perspective
mlab.view(270, 0)
# Add a colorbar if indicated by colorbar_on (=True)
if colorbar_on:
# mlab.colorbar(title='Height (nm)', orientation='vertical')
mlab.colorbar(orientation="vertical")
# Save the figure if indicated by save (=True)
if save:
mlab.savefig(file_path, size=(1000, 1000))
if show == False:
mlab.close()
# Keep the figure open if indicated by show (=True)
if show:
mlab.show()
示例14: field
def field(potential, outfile=None, title="BEM Calculation (field)", cmap="spectral"):
from mayavi import mlab
u,v,w = np.gradient(potential)
obj = mlab.quiver3d(u,v,w, colormap=cmap, vmax=10)
mlab.colorbar()
if outfile:
mlab.savefig(outfile)
return obj
示例15: show
def show(self):
'''Show the 3D diagram in the screen.'''
from mayavi import mlab
self.triangleMesh= mlab.triangular_mesh(self.x, self.y, self.z, self.triangles, scalars= self.scalars)
mlab.colorbar(self.triangleMesh, orientation='vertical')
mlab.outline(self.triangleMesh)
mlab.axes(self.triangleMesh, xlabel= self.axialForceLabel, ylabel= self.bendingMomentYLabel, zlabel= self.bendingMomentZLabel)
#mlab.title(self.title)
mlab.show()