我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用plotly.graph_objs.Scatter3d()。
def plot_traj(self, qt, **kwargs) : if self.vis_mode == '2D' : trajs = self.periodize_traj(qt) for traj in trajs : # (r,theta) -> (y,x) curve = go.Scatter(x = traj[:,1], y = traj[:,0], mode = 'lines', hoverinfo='none', **kwargs) self.current_axis.append(curve) elif self.vis_mode == '3D' : if type(qt[0]) is not list : qt = [qt] if self.upsample_trajs : qt = list( self.upsample(q) for q in qt ) traj = list( self.I(q = q) for q in qt ) separator = array([None]* 3).reshape((1,3)) traj = vstack( vstack((i, separator)) for i in traj ) curve = go.Scatter3d(x = traj[:,0], y = traj[:,1], z = traj[:,2], mode = 'lines', hoverinfo='none', **kwargs) self.current_axis.append(curve) # Vector field display
def quiver_3D(self, qt, vt, **kwargs) : if qt.shape[1] == 2 : Qt = self.I(qt) Vt = self.dI(qt, vt) elif qt.shape[1] == 3 : Qt = qt Vt = vt # quiver3 is not implemented by plotly.js : # we have to settle for a poor derivative... H = Qt T = H + Vt arrows = go.Scatter3d( x = (hstack(tuple( (H[i,0], T[i,0], None) for i in range(T.shape[0]) ))), y = (hstack(tuple( (H[i,1], T[i,1], None) for i in range(T.shape[0]) ))), z = (hstack(tuple( (H[i,2], T[i,2], None) for i in range(T.shape[0]) ))), mode = 'lines', **kwargs ) self.current_axis.append(arrows)
def plotVAEplotly(self, logdir, prefix, ctable=None, reverseUtt=False, batch_size=128, debug=False): ticks = [[-1,-0.5,0,0.5,1]]*self.latentDim samplePoints = np.array(np.meshgrid(*ticks)).T.reshape(-1,3) input_placeholder = np.ones(tuple([len(samplePoints)] + list(self.phon.output_shape[1:-1]) + [1])) preds = self.decode_word([samplePoints, input_placeholder], batch_size=batch_size) if reverseUtt: preds = getYae(preds, reverseUtt) reconstructed = reconstructXae(np.expand_dims(preds.argmax(-1), -1), ctable, maxLen=5) data = [go.Scatter3d( x = samplePoints[:,0], y = samplePoints[:,1], z = samplePoints[:,2], text = reconstructed, mode='text' )] layout = go.Layout() fig = go.Figure(data=data, layout=layout) plotly.offline.plot(fig, filename=logdir + '/' + prefix + '_VAEplot.html', auto_open=False)
def traceStatsPoints(statPoints, dps): statCoords = np.array([np.dot(sp, COORDS) for sp in statPoints]) x, y, z = statCoords.transpose() statTooltips = np.array([tooltipText(sp, v, max(dps)) for (sp, v) in zip(statPoints, dps)]) sizes = 6 + 6 * (dps >= max(dps) - (max(dps) - min(dps)) * 0.05) + 6 * (dps == max(dps)) colors = dps tickValues = generateTickValues(dps, generateTickStep(dps)) tickTexts = generateTickTexts(dps, tickValues) return go.Scatter3d( x=x, y=y, z=z, text=statTooltips, hoverinfo='text', mode='markers', marker=dict( size=sizes, line=dict( color='rgba(32, 32, 32, 0.3)', width=0.5 ), color=colors, colorbar=go.ColorBar( title='DPS', tickvals=tickValues, ticktext=tickTexts, ), colorscale=[ [0., 'rgba(40,55,255, 0.3)'], [0.95, 'rgba(255, 60, 25, 0.7)'], [0.9501, 'rgba(255, 60, 25, 1)'], [0.9999, 'rgba(255, 60, 25, 1)'], [1., 'rgba(25, 225, 55, 1)'] ], ), showlegend=False, )
def traceStatLabels(): x, y, z = COORDS.transpose() return go.Scatter3d( x=x, y=y, z=z, hoverinfo='none', mode='text', text=['Crit', 'Haste', 'Mastery', 'Versatility'], textposition='top', showlegend=False, )
def marker_3D(self, q, **kwargs) : if q.shape[1] == 2 : Q = self.I(q = q) elif q.shape[1] == 3 : Q = q points = go.Scatter3d(x = Q[:,0], y = Q[:,1], z = Q[:,2], mode = 'markers', hoverinfo='name', **kwargs) self.current_axis.append(points)
def show_glyphs(self, scale = 0.03, axis = 'Z') : "Displays triangles on the spherical manifold." if self.mode == 'whole sphere' or self.mode == 'spherical blackboard' : # We will embed self.triangles in the euclidean space R^3, # in the neighborhood of the sphere S(1/2). if axis == 'X' : theta = self.theta phi = self.phi e_theta = vstack( ( -sin(theta) , cos(theta) * cos(phi), cos(theta) * sin(phi) ) ).T e_phi = vstack( ( zeros(theta.shape) , -sin(theta) * sin(phi), sin(theta) * cos(phi) ) ).T elif axis == 'Z' : theta = self.theta_Z phi = self.phi_Z e_theta = - vstack( ( cos(theta) * cos(phi), cos(theta) * sin(phi), -sin(theta) ) ).T e_phi = + vstack( ( - sin(phi), cos(phi), zeros(theta.shape) ) ).T # We don't want glyphs to overlap e_theta = scale * e_theta e_phi = scale * e_phi glyphs = [] separator = [None, None, None] for i in range(self.triangles.shape[0]) : point = array([self.X[i], self.Y[i], self.Z[i]]) glyphs.append(array([ point + real(self.triangles[i,0]) * e_phi[i] + imag(self.triangles[i,0]) * e_theta[i] , # A point + real(self.triangles[i,1]) * e_phi[i] + imag(self.triangles[i,1]) * e_theta[i] , # B point + real(self.triangles[i,2]) * e_phi[i] + imag(self.triangles[i,2]) * e_theta[i] , # C point + real(self.triangles[i,0]) * e_phi[i] + imag(self.triangles[i,0]) * e_theta[i] , # A separator ])) glyphs = vstack(glyphs) curves = go.Scatter3d(x = glyphs[:,0], y = glyphs[:,1], z = glyphs[:,2], mode = 'lines', hoverinfo='none', name = 'Triangles') self.current_axis.append(curves)
def scatter_3d(xs, ys, zs): plotly.offline.plot([Scatter3d( x=xs, y=ys, z=zs, mode='markers' )])
def create_plot(self): # ''' # description: create plotly figure # returns:plotly figure # ''' colormap = self.make_colormap() _lda_keys = self.get_lda_keys() if self.dim =="2d": # reduce the dimesnsions of X_topics # angle value close to 1 means sacrificing accuracy for speed # pca initializtion usually leads to better results tsne_model = TSNE(n_components=2, verbose=1, random_state=0, angle=.99, init='pca') # 20-D -> 2-D tsne_lda = tsne_model.fit_transform(self.X_topics_current) #create tracem trace1 = go.Scatter( x = tsne_lda[:, 0], y = tsne_lda[:, 1], mode = 'markers', marker =dict(color = colormap[_lda_keys]), text= self.titles_current ) data = [trace1] layout = go.Layout(xaxis = dict(visible = False),yaxis = dict(visible = False)) fig2d = go.Figure(data=data, layout = layout) return fig2d #same but with 3d graph else: tsne_model = TSNE(n_components=3, verbose=1, random_state=0, angle=.99, init='pca') # 20-D -> 3-D tsne_lda = tsne_model.fit_transform(self.X_topics_current) trace1 = go.Scatter3d( x = tsne_lda[:, 0], y = tsne_lda[:, 1], z = tsne_lda[:, 2], mode = 'markers', marker = dict(color = colormap[_lda_keys]), text = self.titles_current ) data = [trace1] layout = go.Layout(scene = dict(xaxis = dict(visible = False),yaxis = dict(visible = False), zaxis = dict(visible = False) )) fig3d = go.Figure(data=data, layout = layout) return fig3d