本文整理汇总了Python中mayavi.mlab.axes函数的典型用法代码示例。如果您正苦于以下问题:Python axes函数的具体用法?Python axes怎么用?Python axes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了axes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: animateGIF
def animateGIF(filename, prices):
'''Creates a mayavi visualization of a pd DataFrame containing stock prices
Then uses MoviePy to animate and save as a gif
Inputs:
prices => a pd DataFrame, w/ index: dates; columns: company names
'''
#Imports mlab here to delay starting of mayavi engine until necessary
from mayavi import mlab
#Because of current mayavi requirements, replaces dates and company names with integers
x_length, y_length = prices.shape
xTime = np.array([list(xrange(x_length)),] * y_length).transpose()
yCompanies = np.array([list(xrange(y_length)),] * x_length)
#Sort indexed prices by total return on last date
lastDatePrices = prices.iloc[-1]
lastDatePrices.sort_values(inplace=True)
sortOrder = lastDatePrices.index
zPrices = prices[sortOrder]
#Create mayavi2 object
fig = mlab.figure(bgcolor=(.4,.4,.4))
vis = mlab.surf(xTime, yCompanies, zPrices)
mlab.outline(vis)
mlab.orientation_axes(vis)
mlab.axes(vis, nb_labels=0, xlabel = 'Time', ylabel = 'Company', zlabel = 'Price')
animation = mpy.VideoClip(make_frame, duration = 4).resize(1.0)
animation.write_gif(filename, fps=20)
示例2: labels
def labels(self):
'''
Add 3d text to show the axes.
'''
fontsize = max(self.xrang, self.yrang)/40.
tcolor = (1,1,1)
mlab.text3d(self.xrang/2,-40,self.zrang+40,'R.A.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-40,self.yrang/2,self.zrang+40,'Decl.',scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-40,-40,self.zrang/2-10,'V (km/s)',scale=fontsize,orient_to_camera=True,color=tcolor)
# Label the coordinates of the corners
# Lower left corner
ra0 = self.extent[0]; dec0 = self.extent[2]
c = coord.ICRS(ra=ra0, dec=dec0, unit=(u.degree, u.degree))
RA_ll = str(int(c.ra.hms.h))+'h'+str(int(c.ra.hms.m))+'m'+str(round(c.ra.hms.s,1))+'s'
mlab.text3d(0,-20,self.zrang+20,RA_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
DEC_ll = str(int(c.dec.dms.d))+'d'+str(int(abs(c.dec.dms.m)))+'m'+str(round(abs(c.dec.dms.s),1))+'s'
mlab.text3d(-80,0,self.zrang+20,DEC_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
# Upper right corner
ra0 = self.extent[1]; dec0 = self.extent[3]
c = coord.ICRS(ra=ra0, dec=dec0, unit=(u.degree, u.degree))
RA_ll = str(int(c.ra.hms.h))+'h'+str(int(c.ra.hms.m))+'m'+str(round(c.ra.hms.s,1))+'s'
mlab.text3d(self.xrang,-20,self.zrang+20,RA_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
DEC_ll = str(int(c.dec.dms.d))+'d'+str(int(abs(c.dec.dms.m)))+'m'+str(round(abs(c.dec.dms.s),1))+'s'
mlab.text3d(-80,self.yrang,self.zrang+20,DEC_ll,scale=fontsize,orient_to_camera=True,color=tcolor)
# V axis
if self.extent[5] > self.extent[4]:
v0 = self.extent[4]; v1 = self.extent[5]
else:
v0 = self.extent[5]; v1 = self.extent[4]
mlab.text3d(-20,-20,self.zrang,str(round(v0,1)),scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.text3d(-20,-20,0,str(round(v1,1)),scale=fontsize,orient_to_camera=True,color=tcolor)
mlab.axes(self.field, ranges=self.extent, x_axis_visibility=False, y_axis_visibility=False, z_axis_visibility=False)
mlab.outline()
示例3: plot
def plot(self):
"""Plots the geometry using the package Mayavi."""
print('\nPlot the three-dimensional geometry ...')
from mayavi import mlab
x_init = self.gather_coordinate('x', position='initial')
y_init = self.gather_coordinate('y', position='initial')
z_init = self.gather_coordinate('z', position='initial')
x = self.gather_coordinate('x')
y = self.gather_coordinate('y')
z = self.gather_coordinate('z')
figure = mlab.figure('body', size=(600, 600))
figure.scene.disable_render = False
same = (numpy.allclose(x, x_init, rtol=1.0E-06) and
numpy.allclose(y, y_init, rtol=1.0E-06) and
numpy.allclose(z, z_init, rtol=1.0E-06))
if not same:
mlab.points3d(x_init, y_init, z_init, name='initial',
scale_factor=0.01, color=(0, 0, 1))
mlab.points3d(x, y, z, name='current',
scale_factor=0.01, color=(1, 0, 0))
mlab.axes()
mlab.orientation_axes()
mlab.outline()
figure.scene.disable_render = True
mlab.show()
示例4: draw_working_area
def draw_working_area(self, width, height):
color = (0.9, 0.9, 0.7)
x, y = np.mgrid[0:height+1:10, 0:width+1:10]
z = np.zeros(x.shape)
mlab.surf(x, y, z, color=color, line_width=1.0,
representation='wireframe', warp_scale=self.scale)
mlab.axes()
示例5: visualizePrices
def visualizePrices(prices):
'''Creates a mayavi visualization of a pd DataFrame containing stock prices
Inputs:
prices => a pd DataFrame, w/ index: dates; columns: company names
'''
#Because of mayavi requirements, replace dates and company names with integers
#until workaround is figured out
x_length, y_length = prices.shape
xTime = np.array([list(xrange(x_length)),] * y_length).transpose()
yCompanies = np.array([list(xrange(y_length)),] * x_length)
#Sort indexed prices by total return on last date
lastDatePrices = prices.iloc[-1]
lastDatePrices.sort_values(inplace=True)
sortOrder = lastDatePrices.index
zPrices = prices[sortOrder]
#Create mayavi2 object
dims = xTime.shape
fig = mlab.figure(bgcolor=(.4,.4,.4))
vis = mlab.surf(xTime, yCompanies, zPrices)
mlab.outline(vis)
mlab.orientation_axes(vis)
#mlab.title('S&P 500 Market Data Visualization', size = .25)
mlab.axes(vis, nb_labels=0, xlabel = 'Time', ylabel = 'Company', zlabel = 'Price')
#Functionality to be added:
# cursor3d = mlab.points3d(0., 0., 0., mode='axes',
# color=(0, 0, 0),
# scale_factor=20)
#picker = fig.on_mouse_pick(picker_callback)
mlab.show()
示例6: animateGIF
def animateGIF(filename, prices):
'''Creates a mayavi visualization of a pd DataFrame containing stock prices
Then uses MoviePy to animate and save as a gif
Inputs:
prices => a pd DataFrame, w/ index: dates; columns: company names
'''
#Because of mayavi requirements, replace dates and company names with integers
#until workaround is figured out
x_length, y_length = prices.shape
xTime = np.array([list(xrange(x_length)),] * y_length).transpose()
yCompanies = np.array([list(xrange(y_length)),] * x_length)
#Sort indexed prices by total return on last date
lastDatePrices = prices.iloc[-1]
lastDatePrices.sort_values(inplace=True)
sortOrder = lastDatePrices.index
zPrices = prices[sortOrder]
#Create mayavi2 object
dims = xTime.shape
fig = mlab.figure(bgcolor=(.4,.4,.4))
vis = mlab.surf(xTime, yCompanies, zPrices)
mlab.outline(vis)
mlab.orientation_axes(vis)
mlab.axes(vis, nb_labels=0, xlabel = 'Time', ylabel = 'Company', zlabel = 'Price')
# duration = 2 #Duration of the animation in seconds (will loop)
animation = mpy.VideoClip(make_frame, duration = 4).resize(1.0)
# animation.write_videofile('prototype_animation.mp4', fps=20)
animation.write_gif(filename, fps=20)
示例7: plot_mcontour
def plot_mcontour(self, ndim0, ndim1, z, show_mode):
"use mayavi.mlab to plot contour."
if not mayavi_installed:
self.__logger.info("Mayavi is not installed on your device.")
return
#do 2d interpolation
#get slice object
s = np.s_[0:ndim0:1, 0:ndim1:1]
x, y = np.ogrid[s]
mx, my = np.mgrid[s]
#use cubic 2d interpolation
interpfunc = interp2d(x, y, z, kind='cubic')
newx = np.linspace(0, ndim0, 600)
newy = np.linspace(0, ndim1, 600)
newz = interpfunc(newx, newy)
#mlab
face = mlab.surf(newx, newy, newz, warp_scale=2)
mlab.axes(xlabel='x', ylabel='y', zlabel='z')
mlab.outline(face)
#save or show
if show_mode == 'show':
mlab.show()
elif show_mode == 'save':
mlab.savefig('mlab_contour3d.png')
else:
raise ValueError('Unrecognized show mode parameter : ' +
show_mode)
return
示例8: plot3D
def plot3D(name, X, Y, Z, zlabel):
"""
Plots a 3d surface plot of Z using the mayavi mlab.mesh function.
Parameters
----------
name: string
The name of the figure.
X: 2d ndarray
The x-axis data.
Y: 2d ndarray
The y-axis data.
Z: 2d nd array
The z-axis data.
zlabel: The title that appears on the z-axis.
"""
mlab.figure(name)
mlab.clf()
plotData = mlab.mesh(X/(np.max(X) - np.min(X)),
Y/(np.max(Y) - np.min(Y)),
Z/(np.max(Z) - np.min(Z)))
mlab.outline(plotData)
mlab.axes(plotData, ranges=[np.min(X), np.max(X),
np.min(Y), np.max(Y),
np.min(Z), np.max(Z)])
mlab.xlabel('Space ($x$)')
mlab.ylabel('Time ($t$)')
mlab.zlabel(zlabel)
示例9: etsIntro
def etsIntro():
x, y = np.ogrid[-2:2:20j, -2:2:20j]
z = x * np.exp( - x**2 - y**2)
pl = mlab.surf(x, y, z, warp_scale="auto")
mlab.axes(xlabel='x', ylabel='y', zlabel='z')
mlab.outline(pl)
示例10: plot_mayavi
def plot_mayavi(self):
"""Use mayavi to plot a phenotype phase plane in 3D.
The resulting figure will be quick to interact with in real time,
but might be difficult to save as a vector figure.
returns: mlab figure object"""
from mayavi import mlab
figure = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
figure.name = "Phenotype Phase Plane"
max = 10.0
xmax = self.reaction1_fluxes.max()
ymax = self.reaction2_fluxes.max()
zmax = self.growth_rates.max()
xgrid, ygrid = meshgrid(self.reaction1_fluxes, self.reaction2_fluxes)
xgrid = xgrid.transpose()
ygrid = ygrid.transpose()
xscale = max / xmax
yscale = max / ymax
zscale = max / zmax
mlab.surf(xgrid * xscale, ygrid * yscale, self.growth_rates * zscale,
representation="wireframe", color=(0, 0, 0), figure=figure)
mlab.mesh(xgrid * xscale, ygrid * yscale, self.growth_rates * zscale,
scalars=self.shadow_prices1 + self.shadow_prices2,
resolution=1, representation="surface", opacity=0.75,
figure=figure)
# draw axes
mlab.outline(extent=(0, max, 0, max, 0, max))
mlab.axes(opacity=0, ranges=[0, xmax, 0, ymax, 0, zmax])
mlab.xlabel(self.reaction1_name)
mlab.ylabel(self.reaction2_name)
mlab.zlabel("Growth rates")
return figure
示例11: AortaSinusoidModelingVisualization
def AortaSinusoidModelingVisualization(filename):
path = 'C:\\Users\\shijingliu\\Dropbox\\Reggie\\Results\\Sinusoid Modeling Result (2 seconds window size)\\Aorta Modeling Results\\'
file = filename
finalname = path+file+'.csv'
'declare the x, y, z, s array for point visualization'
index = 0
x_array = []
y_array = []
z_array = []
s_array = []
with open(finalname, 'rb') as csvfile:
rowreader = csv.reader(csvfile)
for row in rowreader:
if index <1:
index = index + 1
else:
s = int(row[0])
x_data = float(row[1])
y_data = float(row[2])
z_data = float(row[3])
if (np.abs(x_data)<=20.0) and (np.abs(y_data)<=20.0) and (np.abs(z_data)<=200.0):
s_array.append(s)
x_array.append(x_data)
y_array.append(y_data)
z_array.append(z_data)
mlab.axes(mlab.outline(mlab.points3d(x_array, y_array, z_array, s_array, colormap="Reds", scale_mode='none')))
示例12: visualizePrices
def visualizePrices(prices):
'''Creates a mayavi visualization of a pd DataFrame containing stock prices
Inputs:
prices => a pd DataFrame, w/ index: dates; columns: company names
'''
#Imports mlab here to delay starting of mayavi engine until necessary
from mayavi import mlab
#Because of current mayavi requirements, replaces dates and company names with integers
x_length, y_length = prices.shape
xTime = np.array([list(xrange(x_length)),] * y_length).transpose()
yCompanies = np.array([list(xrange(y_length)),] * x_length)
#Sort indexed prices by total return on last date
lastDatePrices = prices.iloc[-1]
lastDatePrices.sort_values(inplace=True)
sortOrder = lastDatePrices.index
zPrices = prices[sortOrder]
#Create mayavi2 object
fig = mlab.figure(bgcolor=(.4,.4,.4))
vis = mlab.surf(xTime, yCompanies, zPrices)
mlab.outline(vis)
mlab.orientation_axes(vis)
#mlab.title('S&P 500 Market Data Visualization', size = .25)
mlab.axes(vis, nb_labels=0, xlabel = 'Time', ylabel = 'Company', zlabel = 'Price')
mlab.show()
示例13: plotDensity
def plotDensity(mToB,coeffs,n=100,plotVals="real",plotBnd=True):
"""Plot boundary density with Mayavi
INPUT:
mToB - Mesh-to-Basis map
coeffs - Coefficients of boundary density
n - Discretisation points per element (default 100)
plotVals - "real", "imag" or "abs" for real/imaginary part or absolute values
(default "real")
plotBnd - Also plot boundary of shape (default True)
"""
from mayavi import mlab
transforms={"real":numpy.real,"imag":numpy.imag,"abs":numpy.abs}
x,f=evalDensity(mToB,coeffs,n)
f=transforms[plotVals](f)
xmin=min(x[0])
xmax=max(x[0])
ymin=min(x[1])
ymax=max(x[1])
zmin=max([-1,min(f)])
zmax=min([1,max(f)])
extent=[xmin,xmax,ymin,ymax,zmin,zmax]
ranges=[xmin,xmax,ymin,ymax,min(f),max(f)]
fig=mlab.figure(bgcolor=(1,1,1))
mlab.plot3d(x[0],x[1],f,extent=extent,color=(0,0,0),tube_radius=None,figure=fig)
if plotBnd:
mlab.plot3d(x[0],x[1],numpy.zeros(x[0].shape),extent=[xmin,xmax,ymin,ymax,0,0],tube_radius=None,figure=fig)
mlab.axes(extent=extent,ranges=ranges,line_width=3.0,figure=fig)
mlab.show()
示例14: 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!
示例15: display
def display(self,bgcolor=None,showAxes=False):
mlab.figure(bgcolor=bgcolor)
for x,y,z,op,col in zip(self.xMesh,self.yMesh,self.zMesh,self.meshOpacity,self.meshColor):
mlab.mesh(x,y,z,opacity=op,color=col)
if showAxes:
mlab.axes()
mlab.show()