def draw2DView(figure, raw, seg, index, color=(1,0,0)): """ Draw a 2D maximum intensity projection of the raw data and create a segmentation overlay """ raw2d = np.max(raw, axis = 2) mlab.imshow(raw2d, colormap='gray', figure=figure) sother = np.multiply( (seg != 0).astype(np.int32),(seg != index).astype(np.int32) ) ##max1 = np.max(np.where(np.max(np.max((seg == index).astype(np.int32), axis = 0), axis = 0)!=0))+1 ##min1 = np.min(np.where(np.max(np.max((seg == index).astype(np.int32), axis = 0), axis = 0)!=0)) ##max2 = np.max(np.where(np.max(np.max((seg == index).astype(np.int32), axis = 0), axis = 1)!=0))+1 ##min2 = np.min(np.where(np.max(np.max((seg == index).astype(np.int32), axis = 0), axis = 1)!=0)) ##d1 = int(min(max1-min1-15,0)) ##d2 = int(min(max2-min2-15,0)) ##min1 += d1 ##max1 -= d1 ##min2 += d2 ##max2 -= d2 ##sother = (seg == index).astype(np.int32) ##seg2dother = np.max(sother, axis = 0) ##seg2dother[min2:max2,min1:max1]=1 sindex = (seg == index).astype(np.int32) seg2dother = np.max(sother, axis = 2) seg2dindex = np.max(sindex, axis = 2) mlab.contour_surf(seg2dother, color = (0,0,1), contours = 2, warp_scale = 0, figure=figure) mlab.contour_surf(seg2dindex, color = color, contours = 2, warp_scale = 0, figure=figure)
def test14(self): data = np.loadtxt('./Data/map.csv', delimiter=',') row = data.shape[0] column = data.shape[1] x, y = np.mgrid[0:row:1, 0:column:1] x, y = np.mgrid[0:row:1, 0:column:1] mlab.contour_surf(x, y, data, contours=100) mlab.show()
def mayavi_contour_surf(): """ 绘制contour_surf图 :return: """ x, y = np.mgrid[-5:5:70j, -5:5:70j] # 绘制peaks函数的等高线 mlab.contour_surf(x, y, peaks, contours=9) mlab.colorbar() mlab.show()
def test_contour_surf(): """Test contour_surf on regularly spaced co-ordinates like MayaVi.""" def f(x, y): sin, cos = np.sin, np.cos return sin(x + y) + sin(2 * x - y) + cos(3 * x + 4 * y) x, y = np.mgrid[-7.:7.05:0.1, -5.:5.05:0.05] s = mlab.contour_surf(x, y, f) return s
def cont3(x=None, y=None, z=None, contours=20, f=None, axeLab=['', '', ''], clf=True): """ 3 argument surface plot """ if x == None: x = arange(z.shape[0]) if y == None: y = arange(z.shape[1]) if z == None: z = arange(x.shape[0] * y.shape[0]) if clf: ml.clf(f) if z.ndim == 3: for i in range(z.shape[-1]): ml.contour_surf(sc(x), sc(y), scLike(z[..., i], z[..., 0]), contours=contours, extent=ex, figure=f) axe(axeLab, rgs(x, y, z[..., 0]), f) else: ml.contour_surf(sc(x), sc(y), sc(z), contours=contours, extent=ex, figure=f) axe(axeLab, rgs(x, y, z), f) out() return f
def plot_3d(topo, bottom_z, top_z, time_step, color=(0.88627451, 0.79215686, 0.4627451), ci = 0.1, scale=1, ve=1, dx=1, line_thickness=0.05, contour_switch=False, new_figure=False): """function for plotting a set of bedforms in 3D :param topo: array of stacked topographic surfaces that describe the bedform topography through time :param bottom_z: elevation of the bottom of the model :param top_z: elevation of the bottom of the model (if it is less than the maximum height of the dunes, they will be "eroded") :param time_step: determines how many bedding surfaces will be drawn (default = 4) :param color: color of the 'sand' (that is, of the model) :param ci: contour interval (used only if contour_switch is 'True') :param scale: scale of model (usually best to leave it at 1) :param ve: vertical exaggeration :param dx: horiozntal gridcell size :param line_thickness: thickness of lines drawn, in units of the figure; has to be a relatively small number (default = 0.05) :param contour_switch: determines whether contours are drawn on top of bedforms :param new_figure: determines whether a new mlab figure is created or not """ if new_figure: mlab.figure(bgcolor=(1,1,1)) else: mlab.clf() strat = np.minimum.accumulate(topo[:, :, ::-1], axis=2)[:, :, ::-1] # convert topography to stratigraphy strat2 = strat.copy() strat2[strat<bottom_z] = bottom_z strat2[strat>top_z] = top_z r,c,ts = np.shape(strat2) z = scale*strat2[:,:,ts-1] z1 = strat2[:,:,-1] X1 = scale*(np.linspace(0,r-1,r)*dx) Y1 = scale*(np.linspace(0,c-1,c)*dx) mlab.surf(X1,Y1,z,warp_scale=ve,color=color) if contour_switch: contours = list(np.arange(np.min(strat2[:,:,-1]),np.max(strat2[:,:,-1]),ci*scale)) # list of contour values mlab.contour_surf(X1,Y1,z, contours=contours, warp_scale=ve,color=(0,0,0),line_width=1.0) # updip side: vertices, triangles = create_section(z1[:,0],dx,bottom_z) x = scale*(vertices[:,0]) y = scale*(np.zeros(np.shape(vertices[:,0]))) z = scale*ve*vertices[:,1] mlab.triangular_mesh(x,y,z,triangles,color=color) # downdip side: vertices, triangles = create_section(z1[:,-1],dx,bottom_z) x = scale*(vertices[:,0]) y = scale*((c-1)*dx*np.ones(np.shape(vertices[:,0]))) z = scale*ve*vertices[:,1] mlab.triangular_mesh(x,y,z,triangles,color=color) # left edge: vertices, triangles = create_section(z1[0,:],dx,bottom_z) x = scale*(np.zeros(np.shape(vertices[:,0]))) y = scale*(vertices[:,0]) z = scale*ve*vertices[:,1] mlab.triangular_mesh(x,y,z,triangles,color=color) # right edge: vertices, triangles = create_section(z1[-1,:],dx,bottom_z) x = scale*((r-1)*dx*np.ones(np.shape(vertices[:,0]))) y = scale*(vertices[:,0]) z = scale*ve*vertices[:,1] mlab.triangular_mesh(x,y,z,triangles,color=color) # bottom face of block: vertices = dx*np.array([[0,0],[r-1,0],[r-1,c-1],[0,c-1]]) triangles = [[0,1,3],[1,3,2]] x = scale*(vertices[:,0]) y = scale*(vertices[:,1]) z = scale*bottom_z*np.ones(np.shape(vertices[:,0])) mlab.triangular_mesh(x,y,ve*z,triangles,color=color) min_final_topo = np.min(topo[:,:,-1]) max_final_topo = np.max(topo[:,:,-1]) t_steps = np.hstack((np.arange(0, ts-1, time_step), ts-2)) for layer_n in tqdm(t_steps): # main loop top = strat2[:,0,layer_n+1] # updip side base = strat2[:,0,layer_n] X1 = scale*(dx*np.arange(0,r)) Y1 = scale*(np.zeros(np.shape(base))) Z1 = ve*scale*base mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) if layer_n == ts-2: Z1 = ve*scale*top mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) top = strat2[:,-1,layer_n+1] # downdip side base = strat2[:,-1,layer_n] X1 = scale*(dx*np.arange(0,r)) Y1 = scale*(dx*(c-1)*np.ones(np.shape(base))) Z1 = ve*scale*base mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) if layer_n == ts-2: Z1 = ve*scale*top mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) top = strat2[0,:,layer_n+1] # left edge base = strat2[0,:,layer_n] X1 = scale*(np.zeros(np.shape(base))) Y1 = scale*(dx*np.arange(0,c)) Z1 = ve*scale*base mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) if layer_n == ts-2: Z1 = ve*scale*top mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) top = strat2[-1,:,layer_n+1] # right edge base = strat2[-1,:,layer_n] X1 = scale*(dx*(r-1)*np.ones(np.shape(base))) Y1 = scale*(dx*np.arange(0,c)) Z1 = ve*scale*base mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) if layer_n == ts-2: Z1 = ve*scale*top mlab.plot3d(X1,Y1,Z1,color=(0,0,0),tube_radius=line_thickness) if (bottom_z > np.min(strat[:,:,layer_n])) and (bottom_z < np.max(strat[:,:,layer_n])): contours = measure.find_contours(strat[:,:,layer_n], bottom_z) for i in range(0,len(contours)): x1 = contours[i][:,0] y1 = contours[i][:,1] z1 = np.ones(np.shape(x1)) * bottom_z mlab.plot3d(x1,y1,z1,color=(0,0,0),tube_radius=line_thickness) if (top_z > np.min(strat[:,:,layer_n])) and (top_z < np.max(strat[:,:,layer_n])): contours = measure.find_contours(strat[:,:,layer_n], top_z) for i in range(0,len(contours)): x1 = contours[i][:,0] y1 = contours[i][:,1] z1 = np.ones(np.shape(x1)) * top_z mlab.plot3d(x1,y1,z1,color=(0,0,0),tube_radius=line_thickness)
# -*- coding: utf-8 -*- """ Created on Tue Jul 4 15:51:17 2017 @author: Administrator """ import numpy as np from mayavi import mlab def f(x, y): return np.sin(x - y) + np.cos(x + y) x, y = np.mgrid[-7.:7.05:0.1, -5.:5.05:0.05] con_s = mlab.contour_surf(x, y, f) mlab.show()
from pylab import * from mayavi import mlab DX = 0.01 def f(x, y): return np.sin(x + y) + np.sin(2 * x - y) + np.cos(3 * x + 4 * y) if __name__ == '__main__': fig = mlab.figure(size = (3000, 3000), bgcolor = (1, 1, 1)) x, y = np.mgrid[-7:7.05:DX, -5:5.05:DX] mlab.contour_surf(x, y, f) mlab.savefig(sys.argv[1], size = (3000, 3000))
out[:,j] = out[:,j] + np.maximum(f[:,j + 1] - f[:,j], 0)**2 else: out[:,j] = out[:,j] + np.maximum(f[:,j - 1] - f[:,j], 0)**2 return np.sqrt(out) def update_phi(P, dt): # [Px, Py] = np.gradient(P) up = lsm_grad_magnitude(P, True) down = lsm_grad_magnitude(P, False) #to obtain correct results, down and up are switched # [U, V] = np.gradient(P) # Gmag = gradient_magnitude(U, V) return P + dt * down msurf = mlab.surf(P,colormap='jet') contour2d = mlab.contour_surf(P, contours=[0]) for i in xrange(140): P = update_phi(P, dt) if i % 20 == 0: msurf.mlab_source.scalars = P contour2d.mlab_source.scalars = P # if i % 50 == 0: # Pedt = ndimage.distance_transform_edt(np.round(P)) # P = np.sign(P) * Pedt # P = renormalize(P,1.0) mlab.outline() mlab.axes() mlab.show()
extent=(0.375, 0.625, 0, 0.25, 0, 0.25), colormap='Accent')) plt.outline(plt.mesh(xv, yv, hv, extent=(0.75, 1, 0, 0.25, 0, 0.25), colormap='prism'), color=(.5, .5, .5)) # endsubplot hv = h0 / (1 + (xv**2 + yv**2) / (R**2)) # Default contour plot plotted together with surf. plt.figure(5, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.surf(xv, yv, hv, warp_scale=0.01) plt.contour_surf(xv, yv, hv, warp_scale=0.01) # 10 contour lines (equally spaced contour levels). plt.figure(6, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.contour_surf(xv, yv, hv, contours=10, warp_scale=0.01) # 10 contour lines (equally spaced contour levels) together with surf. # Black color for contour lines. plt.figure(7, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.surf(xv, yv, hv, warp_scale=0.01) plt.contour_surf(xv, yv, hv, contours=10, color=(0., 0., 0.), \ warp_scale=0.01) # Specify the contour levels explicitly as a list. plt.figure(8, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) levels = [500., 1000., 1500., 2000.]
def test05(): x, y = np.mgrid[-7.:7.05:0.1, -5.:5.05:0.05] s = mlab.contour_surf(x, y, f) mlab.show()
x = y = np.linspace(-10., 10., 41) xv, yv = np.meshgrid(x, y, indexing='ij', sparse=False) hv = h0 / (1 + (xv**2 + yv**2) / (R**2)) # Define a coarser grid for the vector field x2 = y2 = np.linspace(-10., 10., 11) x2v, y2v = np.meshgrid(x2, y2, indexing='ij', sparse=False) h2v = h0 / (1 + (x2v**2 + y2v**2) / (R**2)) # Surface on coarse grid # endcoarsergrid dhdx, dhdy = np.gradient(h2v) # Draw contours and gradient field of h plt.figure(11, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.contour_surf(xv, yv, hv, contours=20, warp_scale=0.01) # mode controls the style how vectors are drawn # color controls the colors of the vectors # scale_mode='none' ensures that vectors are drawn with the same length plt.quiver3d(x2v, y2v, 0.01 * h2v, dhdx, dhdy, np.zeros_like(dhdx), mode='arrow', color=(1, 0, 0), scale_mode='none') # end draw contours and gradient field of h raw_input('Press any key to continue')
plt.outline(plt.mesh( xv, yv, hv, extent=(0.375, 0.625, 0, 0.25, 0, 0.25), colormap='Accent')) plt.outline(plt.mesh( xv, yv, hv, extent=(0.75, 1, 0, 0.25, 0, 0.25), colormap='prism'), color=(.5, .5, .5)) # endsubplot hv = h0/(1 + (xv**2+yv**2)/(R**2)) # Default contour plot plotted together with surf. plt.figure(5, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.surf(xv, yv, hv, warp_scale=0.01) plt.contour_surf(xv, yv, hv, warp_scale=0.01) # 10 contour lines (equally spaced contour levels). plt.figure(6, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.contour_surf(xv, yv, hv, contours=10, warp_scale=0.01) # 10 contour lines (equally spaced contour levels) together with surf. # Black color for contour lines. plt.figure(7, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.surf(xv, yv, hv, warp_scale=0.01) plt.contour_surf(xv, yv, hv, contours=10, color=(0., 0., 0.), \ warp_scale=0.01) # Specify the contour levels explicitly as a list. plt.figure(8, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) levels = [500., 1000., 1500., 2000.]
def create_block_diagram(strat, dx, ve, xoffset, yoffset, scale, ci, strat_switch, contour_switch, bottom, topo_min, topo_max): """function for creating a 3D block diagram in Mayavi strat - input array with stratigraphic surfaces dx - size of gridcells in the horizontal direction in 'strat' ve - vertical exaggeration offset - offset in the y-direction relative to 0 scale - scaling factor ci - contour interval strat_switch - 1 if you want to plot stratigraphy on the sides; 0 otherwise contour_switch - 1 if you want to plot contours on the top surface; 0 otherwise bottom - elevation value for the bottom of the block""" r, c, ts = np.shape(strat) z = scale * strat[:, :, ts - 1] if strat_switch == 1: z1 = strat[:, :, 0] else: z1 = strat[:, :, -1] X1 = scale * (xoffset + np.linspace(0, r - 1, r) * dx) Y1 = scale * (yoffset + np.linspace(0, c - 1, c) * dx) mlab.surf(X1, Y1, z, warp_scale=ve, colormap='gist_earth', vmin=scale * topo_min, vmax=scale * topo_max) #, line_width=5.0, representation='wireframe') if contour_switch == 1: contours = list(np.arange(vmin, vmax, ci * scale)) # list of contour values mlab.contour_surf(X1, Y1, z, contours=contours, warp_scale=ve, color=(0, 0, 0), line_width=1.0) gray = (0.6, 0.6, 0.6) # color for plotting sides # updip side: vertices, triangles = create_section(z1[:, 0], dx, bottom) x = scale * (xoffset + vertices[:, 0]) y = scale * (yoffset + np.zeros(np.shape(vertices[:, 0]))) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=gray) # downdip side: vertices, triangles = create_section(z1[:, -1], dx, bottom) x = scale * (xoffset + vertices[:, 0]) y = scale * (yoffset + (c - 1) * dx * np.ones(np.shape(vertices[:, 0]))) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=gray) # left edge (looking downdip): vertices, triangles = create_section(z1[0, :], dx, bottom) x = scale * (xoffset + np.zeros(np.shape(vertices[:, 0]))) y = scale * (yoffset + vertices[:, 0]) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=gray) # right edge (looking downdip): vertices, triangles = create_section(z1[-1, :], dx, bottom) x = scale * (xoffset + (r - 1) * dx * np.ones(np.shape(vertices[:, 0]))) y = scale * (yoffset + vertices[:, 0]) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=gray) # bottom face of block: vertices = dx * np.array([[0, 0], [r - 1, 0], [r - 1, c - 1], [0, c - 1]]) triangles = [[0, 1, 3], [1, 3, 2]] x = scale * (xoffset + vertices[:, 0]) y = scale * (yoffset + vertices[:, 1]) z = scale * bottom * np.ones(np.shape(vertices[:, 0])) mlab.triangular_mesh(x, y, ve * z, triangles, color=gray)
import mayavi.mlab as plt import os from math import * import numpy as np h0 = 22.77 R = 4. x = y = np.linspace(-10.,10.,41) xv, yv = np.meshgrid(x, y, indexing='ij', sparse=False) hv = h0/(1 + (xv**2+yv**2)/(R**2)) # Define a coarser grid for the vector field x2 = y2 = np.linspace(-10.,10.,21) x2v, y2v = np.meshgrid(x2, y2, indexing='ij', sparse=False) h2v = h0/(1 + (x2v**2 + y2v**2)/(R**2)) # Surface on coarse grid # endcoarsergrid dhdx, dhdy = np.gradient(h2v) # Draw contours and gradient field of h plt.figure(9, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.contour_surf(xv, yv, hv, contours=20) # mode controls the style how vectors are drawn # color controls the colors of the vectors # scale_factor controls thelength of the vectors plt.quiver3d(x2v, y2v, h2v, dhdx, dhdy, np.zeros_like(dhdx), mode='arrow', color=(1,0,0), scale_factor=.75) # end draw contours and gradient field of h raw_input('Press any key to continue')
def plot_3d(topo, bottom_z, top_z, time_step, color=(0.88627451, 0.79215686, 0.4627451), ci=0.1, scale=1, ve=1, dx=1, line_thickness=0.05, contour_switch=False, new_figure=False): """function for plotting a set of bedforms in 3D""" if new_figure: mlab.figure(bgcolor=(1, 1, 1)) else: mlab.clf() strat = np.minimum.accumulate( topo[:, :, ::-1], axis=2)[:, :, ::-1] # convert topography to stratigraphy strat2 = strat.copy() strat2[strat < bottom_z] = bottom_z strat2[strat > top_z] = top_z r, c, ts = np.shape(strat2) z = scale * strat2[:, :, ts - 1] z1 = strat2[:, :, -1] X1 = scale * (np.linspace(0, r - 1, r) * dx) Y1 = scale * (np.linspace(0, c - 1, c) * dx) mlab.surf(X1, Y1, z, warp_scale=ve, color=color) if contour_switch: contours = list( np.arange(np.min(strat2[:, :, -1]), np.max(strat2[:, :, -1]), ci * scale)) # list of contour values mlab.contour_surf(X1, Y1, z, contours=contours, warp_scale=ve, color=(0, 0, 0), line_width=1.0) # updip side: vertices, triangles = create_section(z1[:, 0], dx, bottom_z) x = scale * (vertices[:, 0]) y = scale * (np.zeros(np.shape(vertices[:, 0]))) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=color) # downdip side: vertices, triangles = create_section(z1[:, -1], dx, bottom_z) x = scale * (vertices[:, 0]) y = scale * ((c - 1) * dx * np.ones(np.shape(vertices[:, 0]))) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=color) # left edge (looking downdip): vertices, triangles = create_section(z1[0, :], dx, bottom_z) x = scale * (np.zeros(np.shape(vertices[:, 0]))) y = scale * (vertices[:, 0]) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=color) # right edge (looking downdip): vertices, triangles = create_section(z1[-1, :], dx, bottom_z) x = scale * ((r - 1) * dx * np.ones(np.shape(vertices[:, 0]))) y = scale * (vertices[:, 0]) z = scale * ve * vertices[:, 1] mlab.triangular_mesh(x, y, z, triangles, color=color) # bottom face of block: vertices = dx * np.array([[0, 0], [r - 1, 0], [r - 1, c - 1], [0, c - 1]]) triangles = [[0, 1, 3], [1, 3, 2]] x = scale * (vertices[:, 0]) y = scale * (vertices[:, 1]) z = scale * bottom_z * np.ones(np.shape(vertices[:, 0])) mlab.triangular_mesh(x, y, ve * z, triangles, color=color) min_final_topo = np.min(topo[:, :, -1]) max_final_topo = np.max(topo[:, :, -1]) t_steps = np.hstack((np.arange(0, ts - 1, time_step), ts - 2)) for layer_n in tqdm(t_steps): # main loop top = strat2[:, 0, layer_n + 1] # updip side base = strat2[:, 0, layer_n] X1 = scale * (dx * np.arange(0, r)) Y1 = scale * (np.zeros(np.shape(base))) Z1 = ve * scale * base mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) if layer_n == ts - 2: Z1 = ve * scale * top mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) top = strat2[:, -1, layer_n + 1] # downdip side base = strat2[:, -1, layer_n] X1 = scale * (dx * np.arange(0, r)) Y1 = scale * (dx * (c - 1) * np.ones(np.shape(base))) Z1 = ve * scale * base mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) if layer_n == ts - 2: Z1 = ve * scale * top mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) top = strat2[0, :, layer_n + 1] # left edge (looking downdip) base = strat2[0, :, layer_n] X1 = scale * (np.zeros(np.shape(base))) Y1 = scale * (dx * np.arange(0, c)) Z1 = ve * scale * base mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) if layer_n == ts - 2: Z1 = ve * scale * top mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) top = strat2[-1, :, layer_n + 1] # right edge (looking downdip) base = strat2[-1, :, layer_n] X1 = scale * (dx * (r - 1) * np.ones(np.shape(base))) Y1 = scale * (dx * np.arange(0, c)) Z1 = ve * scale * base mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) if layer_n == ts - 2: Z1 = ve * scale * top mlab.plot3d(X1, Y1, Z1, color=(0, 0, 0), tube_radius=line_thickness) if (bottom_z > np.min(strat[:, :, layer_n])) and (bottom_z < np.max( strat[:, :, layer_n])): contours = measure.find_contours(strat[:, :, layer_n], bottom_z) for i in range(0, len(contours)): x1 = contours[i][:, 0] y1 = contours[i][:, 1] z1 = np.ones(np.shape(x1)) * bottom_z mlab.plot3d(x1, y1, z1, color=(0, 0, 0), tube_radius=line_thickness) if (top_z > np.min(strat[:, :, layer_n])) and (top_z < np.max( strat[:, :, layer_n])): contours = measure.find_contours(strat[:, :, layer_n], top_z) for i in range(0, len(contours)): x1 = contours[i][:, 0] y1 = contours[i][:, 1] z1 = np.ones(np.shape(x1)) * top_z mlab.plot3d(x1, y1, z1, color=(0, 0, 0), tube_radius=line_thickness)
import mayavi.mlab as plt import os from math import * import numpy as np h0 = 2277. R = 4. x = y = np.linspace(-10.,10.,41) xv, yv = np.meshgrid(x, y, indexing='ij', sparse=False) hv = h0/(1 + (xv**2+yv**2)/(R**2)) # Define a coarser grid for the vector field x2 = y2 = np.linspace(-10.,10.,11) x2v, y2v = np.meshgrid(x2, y2, indexing='ij', sparse=False) h2v = h0/(1 + (x2v**2 + y2v**2)/(R**2)) # Surface on coarse grid # endcoarsergrid dhdx, dhdy = np.gradient(h2v) # Draw contours and gradient field of h plt.figure(11, fgcolor=(.0, .0, .0), bgcolor=(1.0, 1.0, 1.0)) plt.contour_surf(xv, yv, hv, contours=20, warp_scale=0.01) # mode controls the style how vectors are drawn # color controls the colors of the vectors # scale_mode='none' ensures that vectors are drawn with the same length plt.quiver3d(x2v, y2v, 0.01*h2v, dhdx, dhdy, np.zeros_like(dhdx), mode='arrow', color=(1,0,0), scale_mode='none') # end draw contours and gradient field of h raw_input('Press any key to continue')