How to use the plotly.graph_objs.Scatter3d function in plotly

To help you get started, we’ve selected a few plotly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KMouratidis / EDA_miner / EDA_miner / apps / analyze / Clustering.py View on Github external
model.fit(df[xvars])

    # TODO: Find a meaningful way (metric) to notify the user of model score.
    try:
        layout = [[html.H4(f"Clustering model scored: {model.score(df[xvars])}")]]
    except AttributeError:
        # model without a score function
        layout = [[html.H4(f"No score for this method.")]]

    labels = model.labels_
    # TODO: If Y is given, visualize the (in)correctly grouped points.
    # If we have >=2 variables, visualize the clusters
    if len(xvars) >= 3:

        trace1 = go.Scatter3d(x=df[xvars[0]],
                              y=df[xvars[1]],
                              z=df[xvars[2]],
                              showlegend=False,
                              mode='markers',
                              marker=dict(
                                  color=labels.astype(np.float),
                                  line={'color': 'black', 'width': 1}
                              ))

        layout += [{
            'data': [trace1],
            'layout': layouts.default_2d(xvars[0], xvars[1])
        }]

    elif len(xvars) == 2:
        trace = scatterplot(df[xvars[0]], df[xvars[1]],
github schlegelp / navis / navis / plotting / plotly / graph_objs.py View on Github external
if kwargs.get('by_strahler', False):
        s_index = morpho.strahler_index(neuron, return_dict=True)
        max_strahler = max(s_index.values())
        c = []
        for k, s in enumerate(coords):
            this_c = f'rgba({color[0]},{color[1]},{color[2]},{s_index[s[0]] / max_strahler})'
            # Slabs are separated by a  coordinate -> this is
            # why we need one more color entry
            c += [this_c] * (len(s) + 1)
    else:
        try:
            c = 'rgb{}'.format(color)
        except BaseException:
            c = 'rgb(10,10,10)'

    trace_data = [go.Scatter3d(x=coords[:, 0],
                               y=coords[:, 1],
                               z=coords[:, 2],
                               mode='lines',
                               line=dict(color=c,
                                         width=linewidth),
                               name=name,
                               legendgroup=name,
                               showlegend=True,
                               hoverinfo='none'
                               )]

    # Add soma(s):
    soma = utils.make_iterable(neuron.soma)
    if any(soma):
        # If soma detection is messed up we might end up producing
        # dozens of soma which will freeze the kernel
github WheatonCS / Lexos / lexos / models / k_means_model.py View on Github external
k_means = self._get_k_means()
        reduced_data = self._get_reduced_data()
        k_means_index = k_means.fit_predict(reduced_data)

        # Get file names.
        labels = np.array([self._document_label_map[file_id]
                           for file_id in self._doc_term_matrix.index.values])

        # Get x, y, z coordinates.
        x_value = reduced_data[:, 0]
        y_value = reduced_data[:, 1]
        z_value = reduced_data[:, 2]

        # Create plot for each cluster so the color will differ among clusters.
        data = [
            go.Scatter3d(
                x=x_value[np.where(group_number == k_means_index)],
                y=y_value[np.where(group_number == k_means_index)],
                z=z_value[np.where(group_number == k_means_index)],
                text=labels[np.where(group_number == k_means_index)],
                mode="markers",
                name=f"Cluster {group_number + 1}",
                hoverinfo="text",
                marker=dict(
                    size=12,
                    line=dict(width=1)
                )
            )
            for group_number in np.unique(k_means_index)
        ]

        # Set the layout of the plot, mainly set the background color to grey.
github Imperial-visualizations / Physics-Visualizations / visuals_EM / Electrostatics / Scripts / physics.py View on Github external
for j in range(3):
            i=j
            zz = quad(calc_integrand,0,2*np.pi)[0]
            B = np.append(B,zz,axis=None) #value of 2.5 is heuristic for diagram 

        Currenttrace = go.Scatter3d(name = "dI" + str(ang),
                                    x = [a*np.cos((phi_scal+(ang*iterator))),dI[0]+a*np.cos((phi_scal+(ang*iterator)))], 
                                    y = [a*np.sin((phi_scal+(ang*iterator))),dI[1]+a*np.sin((phi_scal+(ang*iterator)))], 
                                    z = [0,dI[2]], 
                                    line = dict(width = 6,color = 'rgb(250,20,0)'),
                                    marker = dict(size=[0,10],color= 'rgb(250,20,0)',symbol= 'diamond',opacity=1)
                                   )   


        Magtrace = go.Scatter3d(name = "dB" +  str(ang),
                                x = [P[0],0+dB[0]], 
                                y = [P[1],0+dB[1]], 
                                z = [P[2],1+dB[2]],
                                line = dict(width = 6, color = 'rgb(50,100,200)'),
                                marker = dict(size=[0,10],color= 'rgb(50,100,200)',symbol= 'diamond',opacity=1),
                               );

        Rtrace = go.Scatter3d(name = "R" + str(ang),
                              x = [a*np.cos((phi_scal+(ang*iterator))),r_vec[0]+a*np.cos((phi_scal+(ang*iterator)))],
                              y = [a*np.sin((phi_scal+(ang*iterator))),r_vec[1]+a*np.sin((phi_scal+(ang*iterator)))],
                              z = [0,r_vec[2]], 
                              line = dict(width = 6, color = 'rgb(0,220,0)'),
                              marker = dict(size=[0,10],color= 'rgb(0,220,0)',symbol= 'diamond',opacity=1),
                             );
github Imperial-visualizations / Physics-Visualizations / visuals_EM / boundaries_JSON_output.py View on Github external
def create_sinusoids(self):
        """Creates the sinusoidal wave components"""
        z_range = np.linspace(0, 1, 100)
        if self.polarisation == "s":
            E_sine = np.array([np.zeros_like(z_range), self.E_0 * -np.sin(self.k * z_range), z_range])
            B_sine = np.array([self.B_0 * -np.sin(self.k * z_range), np.zeros_like(z_range), z_range])
        else:
            E_sine = np.array([self.E_0 * np.sin(self.k * z_range), np.zeros_like(z_range), z_range])
            B_sine = np.array([np.zeros_like(z_range), self.B_0 * -np.sin(self.k * z_range), z_range])
        
        rot_E_sine = self.rotate_sinusoid(E_sine, self.theta, self._x_reflect)
        rot_B_sine = self.rotate_sinusoid(B_sine, self.theta, self._x_reflect)
        
        E_trace = go.Scatter3d(x=rot_E_sine[0].tolist(), y=rot_E_sine[1].tolist(), z=rot_E_sine[2].tolist(),
                               showlegend = False, mode = 'lines', marker = dict(color='#0099FF'))
        B_trace = go.Scatter3d(x=rot_B_sine[0].tolist(), y=rot_B_sine[1].tolist(), z=rot_B_sine[2].tolist(),
                               showlegend = False, mode = 'lines', marker = dict(color='#FF0099'))
        
        return [E_trace, B_trace]
github schlegelp / navis / navis / plotting / _plotting.py View on Github external
marker=dict(
                                color='rgb%s' % str(c),
                                size=2
                            ),
                            name=syn_lay[j]['name'] + ' of ' + neuron_name,
                            showlegend=True,
                            hoverinfo='none'
                        ))
                    elif syn_lay['display'] == 'lines':
                        # Find associated treenode
                        tn = neuron.nodes.set_index('node_id').ix[this_cn.node_id.values]
                        x_coords = [n for sublist in zip(this_cn.x.values * -1, tn.x.values * -1, [None] * this_cn.shape[0]) for n in sublist]
                        y_coords = [n for sublist in zip(this_cn.y.values * -1, tn.y.values * -1, [None] * this_cn.shape[0]) for n in sublist]
                        z_coords = [n for sublist in zip(this_cn.z.values * -1, tn.z.values * -1, [None] * this_cn.shape[0]) for n in sublist]

                        trace_data.append(go.Scatter3d(
                            x=x_coords,
                            y=z_coords,  # y and z are switched
                            z=y_coords,
                            mode='lines',
                            line=dict(
                                color='rgb%s' % str(c),
                                width=5
                            ),
                            name=syn_lay[j]['name'] + ' of ' + neuron_name,
                            showlegend=True,
                            hoverinfo='none'
                        ))

        for i, neuron in enumerate(dotprops.itertuples()):
            # Prepare lines - this is based on nat:::plot3d.dotprops
            halfvect = neuron.points[
github Imperial-visualizations / Physics-Visualizations / visuals_maths / maths_examples / pointslinesplanes / line.py View on Github external
def goify(self,layout=None):
        """Export the line into graphics object
        @author Nick Metelski
        @since 26.07.17"""
        xx, yy, zz = self.getXYZ()
        line = go.Scatter3d(
            mode="lines",
            x=list(xx),
            y=list(yy),
            z=list(zz),
            line = dict(
                color = ('rgb(205, 12, 24)'),
                width = 10)
        )
        return line
github amir-abdi / prob-shape-completion / src / common / utils.py View on Github external
z=landmark[:, 2],
            mode='text',
            text=labels,
            marker=dict(
                size=20,
                line=dict(
                    color='rgba(255, 0, 217, 1)',
                    width=20
                ),
                opacity=1
            ),
            name='landmarks_names'
        )
        data.append(trace2)

        trace3 = go.Scatter3d(
            x=landmark[:, 0],
            y=landmark[:, 1],
            z=landmark[:, 2],
            mode='markers',
            marker=dict(
                size=10,
                line=dict(
                    color='rgba(255, 0, 217, 1)',
                    width=0
                ),
                opacity=1
            ),
            name='landmarks1'
        )
        data.append(trace3)
github LCAV / pyroomacoustics / pyroomacoustics / doa / plotters.py View on Github external
if not hasattr(colatitude, '__iter__'):
            colatitude_ref = [colatitude]
            azimuth = [azimuth]
            x_recon = [x_recon]
            y_recon = [y_recon]
            z_recon = [z_recon]

        text_str3 = []
        for count, colatitude0 in enumerate(colatitude):
            text_str3.append(
                u'({0:.2f}\N{DEGREE SIGN}, {1:.2f}\N{DEGREE SIGN})'.format(np.degrees(colatitude0),
                                                                           np.degrees(azimuth[count]))
            )

        trace3 = go.Scatter3d(mode='markers', name='reconstruction',
                              x=x_recon, y=y_recon, z=z_recon,
                              text=text_str3,
                              hoverinfo='name+text',
                              marker=dict(size=6, symbol='diamond', opacity=0.6,
                                          line=dict(
                                              color='rgb(204, 204, 204)',
                                              width=2
                                          ),
                                          color='rgb(0.850, 0.325, 0.098)'))
        traces.append(trace3)

    data = go.Data(traces)

    layout = go.Layout(title='', autosize=False,
                       width=670, height=550, showlegend=True,
                       margin=go.Margin(l=45, r=45, b=55, t=45)