def show(self, title): figs = [] for ind_f in range(len(self.frames)): (points, triangles, signals) = self.frames[ind_f] points = array(points) triangles = array(triangles) signals = array(signals) signals_per_triangle = list( (signals[triangles[i, 0]] + signals[triangles[i, 1]] + signals[triangles[i, 2]]) / 3 for i in range(triangles.shape[0])) signals_per_triangle[0] += 0.001 # Validate colormap my_colormap = FF._validate_colors("Portland", 'tuple') newdata = FF._trisurf(x=points[:, 2], y=points[:, 0], z=points[:, 1], colormap=my_colormap, simplices=triangles, color_func=signals_per_triangle, plot_edges=False, edges_color='rgb(50, 50, 50)', show_colorbar=False, data_list=True) figs += newdata axis = dict(showbackground=True, backgroundcolor='rgb(230, 230, 230)', gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)') xaxis = axis.copy() xaxis['range'] = [-0.08, 0.09] yaxis = axis.copy() yaxis['range'] = [-0.11, 0.05] zaxis = axis.copy() zaxis['range'] = [0.02, 0.18] aspectratio = dict(x=1, y=1, z=1) layout = graph_objs.Layout(title=title, width='100%', height=800, scene=graph_objs.Scene( xaxis=graph_objs.XAxis(xaxis), yaxis=graph_objs.YAxis(yaxis), zaxis=graph_objs.ZAxis(zaxis), aspectratio=dict(x=aspectratio['x'], y=aspectratio['y'], z=aspectratio['z']), )) return my_iplot(graph_objs.Figure(data=figs, layout=layout))
def show_function(self, f, faces=True, contours=True, name='f'): "Displays a function f(phi, theta)." # Trisurf plot if faces: (points, triangles, signals_per_triangle) = self.mesh(f) points = array(points) triangles = array(triangles) #signals = array(signals) signals_per_triangle = array(signals_per_triangle) #signals_per_triangle = list( (signals[triangles[i,0]] + signals[triangles[i,1]] + signals[triangles[i,2]]) / 3 # for i in range(triangles.shape[0]) ) signals_per_triangle[0] += 0.00001 # Validate colormap my_colormap = FF._validate_colors("LinLhot", 'tuple') newdata = my_trisurf(x=points[:, 0], y=points[:, 1], z=points[:, 2], colormap=my_colormap, simplices=triangles, color_func=signals_per_triangle, plot_edges=False, edges_color='rgb(50, 50, 50)', show_colorbar=True, data_list=True, minmax_values=(0, max(signals_per_triangle))) self.current_axis += newdata # 3D contour plot if contours: R = 1.005 if f == 'density': name = 'Density' if self.mode == 'whole sphere': den = pad(pad(self.density, (0, 1), 'wrap'), (1, 0), 'edge') else: den = pad(self.density, 1, 'edge') values = (den[1:, 1:] + den[0:-1, 1:] + den[1:, 0:-1] + den[0:-1, 0:-1]) / 4. else: fv = vectorize(f) values = fv(self.theta_grid.T, self.phi_grid.T) levels = linspace(0, amax(values), 10) for level in levels: contours = find_contours(values, level) ntheta = self.theta_grid.shape[1] - 1 nphi = self.theta_grid.shape[0] - 1 if self.mode == 'whole sphere': theta = lambda x: pi * x[0] / ntheta phi = lambda x: pi * (2 * x[1] / nphi - 1) elif self.mode == 'spherical blackboard': theta = lambda x: (pi / 2) * x[0] / ntheta phi = lambda x: (pi / 3) * (x[1] / nphi - 1) #points3D = [ ( [ ( R* cos(pi* thph[0]/ntheta), # R* sin(pi* thph[0]/ntheta) * cos(pi*(2*thph[1]/nphi-1)), # R* sin(pi* thph[0]/ntheta) * sin(pi*(2*thph[1]/nphi-1)) ) # for thph in contour ] # + [(None, None, None)] ) # for contour in contours] points3D = [ ([(R * sin(theta(thph)) * cos(phi(thph)), R * sin(theta(thph)) * sin(phi(thph)), R * cos(theta(thph))) for thph in contour] + [(None, None, None)]) for contour in contours ] if points3D != []: contours3D = vstack(points3D) curves = go.Scatter3d(x=contours3D[:, 0], y=contours3D[:, 1], z=contours3D[:, 2], mode='lines', hoverinfo='none', line=dict(width=3, color='red'), name=(name + ' = ' + "{:.2f}".format(level))) self.current_axis.append(curves)