示例#1
0
    def add_surface(self, xyz, triangles, lighting=None, **kwargs):
        """Add a surface model to the plotly figure.

        xyz : array, shape (n_vertices, 3)
            An xyz array defining the position of each vertex in 3-D
        triangles : array, shape (n_triangles, 3)
            An ijk array defining triangles for the mesh. Each row
            indexes 3 rows of in xyz, which together make a triangle.
        lighting : None | dict
            A dictionary specifying lighting parameters in plotly
        """
        if lighting is None:
            lighting = dict(ambient=.4, specular=1)
        self.xyz = xyz
        self.x = xyz.T[0]
        self.y = xyz.T[1]
        self.z = xyz.T[2]
        self.triangles = triangles
        self.xrange = np.array([xyz.min(0)[0], xyz.max(0)[0]])
        self.yrange = np.array([xyz.min(0)[1], xyz.max(0)[1]])
        self.zrange = np.array([xyz.min(0)[2], xyz.max(0)[2]])

        colors = self.cmap(np.repeat(.5, len(triangles)))
        colors = array_to_plotly(colors)
        self.surfacedata = ff._trisurf(
            x=self.x, y=self.y, z=self.z, simplices=self.triangles,
            color_func=colors, **kwargs)
        self.surfacedata[0]['lighting'] = lighting
        self.facecolors = self.surfacedata[0]['facecolor'].copy()
        self.tri_centroids = xyz[triangles].mean(1)
        self.layout['scene'].update(dict(xaxis=dict(range=self.xrange),
                                         yaxis=dict(range=self.yrange),
                                         zaxis=dict(range=self.zrange)))
示例#2
0
    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))
示例#3
0
    def add_surface(self, xyz, triangles, lighting=None, **kwargs):
        """Add a surface model to the plotly figure.

        xyz : array, shape (n_vertices, 3)
            An xyz array defining the position of each vertex in 3-D
        triangles : array, shape (n_triangles, 3)
            An ijk array defining triangles for the mesh. Each row
            indexes 3 rows of in xyz, which together make a triangle.
        lighting : None | dict
            A dictionary specifying lighting parameters in plotly
        """
        if lighting is None:
            lighting = dict(ambient=.4, specular=1)
        self.xyz = xyz
        self.x = xyz.T[0]
        self.y = xyz.T[1]
        self.z = xyz.T[2]
        self.triangles = triangles
        self.xrange = np.array([xyz.min(0)[0], xyz.max(0)[0]])
        self.yrange = np.array([xyz.min(0)[1], xyz.max(0)[1]])
        self.zrange = np.array([xyz.min(0)[2], xyz.max(0)[2]])

        colors = self.cmap(np.repeat(.5, len(triangles)))
        colors = array_to_plotly(colors)
        self.surfacedata = ff._trisurf(x=self.x,
                                       y=self.y,
                                       z=self.z,
                                       simplices=self.triangles,
                                       color_func=colors,
                                       **kwargs)
        self.surfacedata[0]['lighting'] = lighting
        self.facecolors = self.surfacedata[0]['facecolor'].copy()
        self.tri_centroids = xyz[triangles].mean(1)
        self.layout['scene'].update(
            dict(xaxis=dict(range=self.xrange),
                 yaxis=dict(range=self.yrange),
                 zaxis=dict(range=self.zrange)))
示例#4
0
 def init_graph(self, plot_args, plot_kwargs):
     if hasattr(FF, '_trisurf'):
         trisurf = FF._trisurf(*plot_args[:-1], **plot_kwargs)
     else:
         trisurf = trisurface(*plot_args, **plot_kwargs)
     return trisurf[0]
示例#5
0
 def init_graph(self, plot_args, plot_kwargs):
     if hasattr(FF, '_trisurf'):
         trisurf = FF._trisurf(*plot_args[:-1], **plot_kwargs)
     else:
         trisurf = trisurface(*plot_args, **plot_kwargs)
     return trisurf[0]