Exemple #1
0
def scatter3d(traces, columns, title, out_path):
    data = []
    for trace in traces:
        data.append(
            go.Scatter3d(
                x=trace[columns[0]].values,
                y=trace[columns[1]].values,
                z=trace[columns[2]].values,
                mode='markers',
                marker=dict(
                    size=6,
                    #line=dict(
                    #color='rgba(217, 217, 217, 0.14)',
                    #width=5
                    #),
                    opacity=0.8)))
    layout = go.Layout(
        title=title,
        #hovermode='closest',
        scene=Scene(xaxis=XAxis(title=columns[0]),
                    yaxis=YAxis(title=columns[1]),
                    zaxis=ZAxis(title=columns[2])),
        showlegend=True)
    fig = go.Figure(data=data, layout=layout)

    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
    #with open("scatter3.txt", 'w') as fw:
    #    fw.write(offpy(fig, show_link=False, include_plotlyjs=False, output_type='div'))
    return offpy(fig,
                 show_link=False,
                 include_plotlyjs=False,
                 output_type='div')
Exemple #2
0
def scatter_by_cluster(traces, columns, title, axis_labels, out_path):
    data = []
    for trace in traces:
        data.append(
            go.Scatter(
                x=trace[columns[0]].values,
                y=trace[columns[1]].values,
                name=trace[columns[2]].values[0],
                mode="markers",
                marker=dict(size=8,
                            # color='rgba(255, 182, 193, .9)',
                            )))

    layout = go.Layout(title=title,
                       hovermode='closest',
                       xaxis=dict(
                           title=axis_labels[0],
                           ticklen=5,
                           zeroline=False,
                           gridwidth=2,
                       ),
                       yaxis=dict(
                           title=axis_labels[1],
                           ticklen=5,
                           gridwidth=2,
                       ),
                       showlegend=True)

    fig = go.Figure(data=data, layout=layout)
    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
    return offpy(fig,
                 show_link=False,
                 include_plotlyjs=False,
                 output_type='div')
def top_words_prob_plot(all_top_words):
    from plotly.subplots import make_subplots

    fig = make_subplots(rows=len(all_top_words), cols=1)
    for i, top_words in enumerate(all_top_words):
        x = [x[0].strip('Ġ') for x in top_words]
        y = [x[1] for x in top_words]



        trace = go.Bar(
            x=x,
            y=y,
            name=str(i)
        )
        fig.add_trace(trace, row=i+1, col=1)

    fig.update_layout(
        autosize=False,
        width=500,
        height=1000,

        yaxis=dict(
                    title='Entropy',
                    titlefont_size=10,
                    tickfont_size=10,
                ),

    )
    offpy(fig, filename="top_words.html", auto_open=True, show_link=False)
def barchart(x, y):
    assert len(x) == len(y), "the x and y should be the same length"
    #x = [str(i)+" "+str(xi) for i, xi in enumerate(x)]

    fig = go.Figure()


    trace = go.Bar(
        x=x,
        y=y,
    )
    fig.add_trace(trace)

    fig.update_layout(
        title='',
        xaxis_tickfont_size=23,
        yaxis=dict(
            title='KL-Divergence',
            titlefont_size=20,
            tickfont_size=20,
        ),
        legend=dict(
            x=0,
            y=1.0,
            bgcolor='rgba(255, 255, 255, 0)',
            bordercolor='rgba(255, 255, 255, 0)'
        ),
        barmode='group',
        bargap=0.05,  # gap between bars of adjacent location coordinates.
        bargroupgap=0.1  # gap between bars of the same location coordinate.
    )


    offpy(fig, filename="barchart.html", auto_open=True, show_link=False)
Exemple #5
0
def bar_chart_plot(x, y, title, out_path):
    data = [go.Bar(x=x, y=y)]

    layout = go.Layout(title=title)
    fig = go.Figure(data=data, layout=layout)

    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
Exemple #6
0
def time_series_plot(x,y):
    data = [go.Scatter(
        x=x,
        y=y)]

    fig = go.Figure(data=data)

    offpy(fig, filename="dd", auto_open=True, show_link=False)
Exemple #7
0
def bar_chart_plot(x,y):
    data = [go.Bar(
        x=x,
        y=y
    )]

    fig = go.Figure(data=data)

    offpy(fig, filename="dd", auto_open=True, show_link=False)
Exemple #8
0
def three_d_nework_graph(x_positions, y_positions, z_positions, colors, labels = "unknown"):
    trace2=Scatter3d(x=x_positions,
                   y=y_positions,
                   z=z_positions,
                   mode='markers',
                   name='actors',
                   marker=Marker(symbol='dot',
                                 size=6,
                                 color=colors,
                                 colorscale='Viridis',
                                 line=Line(color='rgb(50,50,50)', width=0.5)
                                 ),
                   text=labels,
                   hoverinfo='text'
                   )
    axis=dict(showbackground=True,
              showline=True,
              zeroline=True,
              showgrid=True,
              showticklabels=True,
              title=''
              )
    layout = Layout(
             title="Network of coappearances of documents in the whole repository(3D visualization)",
             width=1000,
             height=1000,
             showlegend=False,
             scene=Scene(
             xaxis=XAxis(axis),
             yaxis=YAxis(axis),
             zaxis=ZAxis(axis),
            ),
         margin=Margin(
            t=100
        ),
        hovermode='closest',
        annotations=Annotations([
               Annotation(
               showarrow=False,
                text="",
                xref='paper',
                yref='paper',
                x=0,
                y=0.1,
                xanchor='left',
                yanchor='bottom',
                font=Font(
                size=14
                )
                )
            ]),    )
    data=Data([trace2])
    fig=Figure(data=data, layout=layout)


    offpy(fig, filename="dd", auto_open=True, show_link=False)
Exemple #9
0
def time_series_plot(x, y):
    data = [go.Scatter(x=x, y=y)]
    '''
    layout = go.Layout(xaxis=dict(
        range=[to_unix_time(datetime.datetime(2013, 10, 17)),
               to_unix_time(datetime.datetime(2013, 11, 20))]
    ))
    '''
    fig = go.Figure(data=data)

    offpy(fig, filename="dd", auto_open=True, show_link=False)
Exemple #10
0
def visualize_topics(phi, words, num_topics, viz_threshold=9e-3):
    phi_viz = np.transpose(phi)
    words_to_display = ~np.all(phi_viz <= viz_threshold, axis=1)
    words_viz = [words[i] for i in range(len(words_to_display)) if words_to_display[i]]
    phi_viz = phi_viz[words_to_display]

    trace = go.Heatmap(z=phi_viz,
                       x=['Topic ' + str(i) for i in range(1, num_topics + 1)],
                       y=words_viz)
    data = [trace]
    fig = go.Figure(data=data)
    offpy(fig, filename="visualize_topics.html", auto_open=True, show_link=False)
def multi_barchart(x, y, z, names):
    assert len(x) == len(y) == len(z), "the lengths should be the same"
    #x = [str(i) + " " + str(xi) for i, xi in enumerate(x)]

    fig = go.Figure()
    fig.add_trace(go.Bar(
        x=x,
        y=y,
        name=names[0]
    ))

    fig.add_trace(go.Bar(
        x=x,
        y=z,
        name=names[1]
    ))

    fig.update_layout(
        title='',
        xaxis_tickfont_size=23,
        yaxis=dict(
            title='Entropy',
            titlefont_size=20,
            tickfont_size=20,
        ),
        legend=dict(
            x=0,
            y=1.0,
            bgcolor='rgba(255, 255, 255, 0)',
            bordercolor='rgba(255, 255, 255, 0)',
            font=dict(
                family="sans-serif",
                size=20,
                color="black"
            ),
        ),
        barmode='group',
        bargap=0.05,  # gap between bars of adjacent location coordinates.
        bargroupgap=0.1  # gap between bars of the same location coordinate.

    # legend = dict(
    #     x=0,
    #     y=1,
    #     traceorder="normal",
    #
    #     bgcolor="LightSteelBlue",
    #     bordercolor="Black",
    #     borderwidth=2
    # )
    )

    offpy(fig, filename="multi_barchart.html", auto_open=True, show_link=False)
Exemple #12
0
def heamap(x, y, z, title, out_path="."):
    trace = go.Heatmap(z=z, x=x, y=y, colorscale='Jet')
    data = [trace]

    layout = dict(yaxis=dict(tickmode="array"), )

    fig = go.Figure(data=data, layout=layout)

    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
    return offpy(fig,
                 show_link=False,
                 include_plotlyjs=False,
                 output_type='div')
Exemple #13
0
def scatter_plot(x, y, colors, names, output_file):

    trace = go.Scatter(x=x,
                       y=y,
                       text=names,
                       mode='markers',
                       marker=dict(size=5,
                                   color=colors,
                                   line=dict(width=1, color='rgb(0, 0, 0)')))

    data = [trace]
    fig = go.Figure(data=data)

    offpy(fig, filename=output_file + ".html", auto_open=True, show_link=False)
Exemple #14
0
def stacked_bar_char(feature_counts_df, title, out_path):
    data = []

    feature_names = list(feature_counts_df.columns.values)
    for index, row in feature_counts_df.iterrows():
        counts = []
        for feature_name in feature_names:
            counts.append(row[feature_name])
        trace = go.Bar(x=feature_names, y=counts, name=str(index))
        data.append(trace)

    layout = go.Layout(barmode='stack')
    fig = go.Figure(data=data, layout=layout)
    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
Exemple #15
0
def boxplot(x_data, y_data, title, out_path="."):
    traces = []

    for xd, yd in zip(x_data, y_data):
        traces.append(
            go.Box(
                y=yd,
                name="_" + str(xd) + "_",
                boxpoints='all',
                jitter=0.5,
                whiskerwidth=0.2,
                #fillcolor=cls,
                marker=dict(size=2, ),
                line=dict(width=1),
            ))

    layout = go.Layout(
        title=title,
        yaxis=dict(
            autorange=True,
            showgrid=True,
            zeroline=True,
            #dtick=5,
            gridcolor='rgb(255, 255, 255)',
            gridwidth=1,
            zerolinecolor='rgb(255, 255, 255)',
            zerolinewidth=2,
        ),
        margin=dict(
            l=40,
            r=30,
            b=80,
            t=100,
        ),
        #paper_bgcolor='rgb(243, 243, 243)',
        #plot_bgcolor='rgb(243, 243, 243)',
        showlegend=True,
    )

    fig = go.Figure(data=traces, layout=layout)
    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
    return offpy(fig,
                 show_link=False,
                 include_plotlyjs=False,
                 output_type='div')
Exemple #16
0
def bar_chart_plot(x, y, title):
    data = [ go.Bar(
        x=x,
        y=y
    ) ]
    layout = go.Layout(title=title)
    fig = go.Figure(data=data, layout=layout) 
    return offpy(fig,include_plotlyjs=False,show_link=False,output_type='div')
Exemple #17
0
def scatter3d_plot(x, y, z, names, colors=None, output_file=None):
    if colors is None:
        colors = 'rgba(10, 10, 10, 0.9)'

    trace = go.Scatter3d(x=x,
                         y=y,
                         z=z,
                         text=names,
                         mode='markers',
                         marker=dict(size=3,
                                     color=colors,
                                     line=dict(
                                         color='rgba(217, 217, 217, 0.14)',
                                         width=0.5),
                                     opacity=1))
    data = [trace]
    fig = go.Figure(data=data)

    offpy(fig, filename=output_file + ".html", auto_open=True, show_link=False)
Exemple #18
0
def bar_chart_plot(x, y, text, info, title):
    trace1 = go.Bar(
        x=x,
        y = y,
        text = text,
        name = info,
    )
    data = [ trace1 ]
    layout = go.Layout(title=title)
    fig = go.Figure(data=data, layout=layout)
    return offpy(fig,include_plotlyjs=False,show_link=False,output_type='div')
Exemple #19
0
def scatter(x, y, title, axis_labels, out_path):
    trace = go.Scatter(x=x, y=y, mode='markers')
    layout = go.Layout(title=title,
                       hovermode='closest',
                       xaxis=dict(
                           title=axis_labels[0],
                           ticklen=5,
                           zeroline=False,
                           gridwidth=2,
                       ),
                       yaxis=dict(
                           title=axis_labels[1],
                           ticklen=5,
                           gridwidth=2,
                       ),
                       showlegend=False)

    data = [trace]
    fig = go.Figure(data=data, layout=layout)
    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
Exemple #20
0
def frequency_trend_plot(x, y):
    data = [go.Scatter(
        x=x,
        y=y,
        line=dict(
            color=('rgb(205, 12, 24)'),
            width=4)
    )]

    layout = go.Layout(
        title='Trend Over Time',
        xaxis=dict(
            title='Normalized Time'
        ),
        yaxis=dict(
            title='Frequency per month'
        )
    )

    fig = go.Figure(data=data, layout=layout)

    offpy(fig, filename="dd", auto_open=True, show_link=False)
Exemple #21
0
def visualize_evolution(psi, phi, words, num_topics):
    topic_words = []
    for i in range(num_topics):
        words_indices = np.argsort(phi[i, :])[:10]
        topic_words.append([words[j] for j in words_indices])

    xs = np.linspace(0, 1, num=1000)
    data = []
    for i in range(len(psi)):
        ys = [
            math.pow(1 - x, psi[i][0] - 1) * math.pow(x, psi[i][1] - 1) /
            scipy.special.beta(psi[i][0], psi[i][1]) for x in xs
        ]
        trace = go.Scatter(x=xs, y=ys, name=', '.join(topic_words[i]))
        data.append(trace)

    layout = go.Layout(
        xaxis=dict(autorange=True,
                   showgrid=True,
                   zeroline=True,
                   showline=False,
                   autotick=True,
                   ticks='',
                   showticklabels=False),
        yaxis=dict(autorange=True,
                   showgrid=True,
                   zeroline=True,
                   showline=False,
                   autotick=True,
                   ticks='',
                   showticklabels=False),
    )
    fig = go.Figure(data=data, layout=layout)
    offpy(fig,
          filename="visualize_evolution.html",
          auto_open=True,
          show_link=False)
Exemple #22
0
def segments_plot(y, vertical_lines, title, out_path):
    trace = go.Scatter(y=y, )

    lines = []
    for vertical_line in vertical_lines:
        lines.append({
            'type': 'line',
            'x0': 0,
            'y0': vertical_line,
            'x1': len(y),
            'y1': vertical_line,
            'opacity': 0.7,
            'line': {
                'color': 'red',
                'width': 2.5,
            },
        })
    layout = {
        'title': title,
        'shapes': lines,
        'yaxis': {
            'title': "Value"
        },
        'xaxis': {
            'title': "Sorted Index"
        }
    }

    data = [trace]
    fig = {
        'data': data,
        'layout': layout,
    }
    # fig = go.Figure(data=data, layout=layout)
    out_file = os.path.join(out_path, str(title) + ".html")
    offpy(fig, filename=out_file, auto_open=True, show_link=False)
def visualize_graph(G,
                    node_labels,
                    node_sizes=[],
                    edge_weights=[],
                    layout="graphviz",
                    filename="netwrokx",
                    title=""):
    positions = reformat_graph_layout(G, layout)

    edge_trace = Scatter(x=[],
                         y=[],
                         line=Line(width=[], color='rgba(136, 136, 136, .8)'),
                         hoverinfo='none',
                         mode='lines')

    for edge in G.edges():
        x0, y0 = positions[edge[0]]
        x1, y1 = positions[edge[1]]
        edge_trace['x'] += [x0, x1, None]
        edge_trace['y'] += [y0, y1, None]

    if edge_weights:
        for weight in edge_weights:
            edge_trace['line']['width'].append(weight)
    else:
        edge_trace['line']['width'] = [1] * len(G.edges())

    node_trace = Scatter(
        x=[],
        y=[],
        text=[],
        mode='markers+text',
        textfont=dict(family='Calibri (Body)', size=25, color='black'),
        opacity=100,
        # hoverinfo='text',
        marker=Marker(
            showscale=True,
            # colorscale options
            # 'Greys' | 'Greens' | 'Bluered' | 'Hot' | 'Picnic' | 'Portland' |
            # Jet' | 'RdBu' | 'Blackbody' | 'Earth' | 'Electric' | 'YIOrRd' | 'YIGnBu'
            colorscale='Jet',
            reversescale=True,
            color=[],
            size=[],
            colorbar=dict(thickness=15,
                          title='Node Connections',
                          xanchor='left',
                          titleside='right'),
            line=dict(width=2)))

    for node in G.nodes():
        x, y = positions[node]
        node_trace['x'].append(x)
        node_trace['y'].append(y)

    for adjacencies in G.adjacency_list():
        node_trace['marker']['color'].append(len(adjacencies))

    if not node_labels:
        node_labels = G.nodes()

    for node in node_labels:
        node_trace['text'].append(node)

    if node_sizes:
        for size in node_sizes:
            node_trace['marker']['size'].append(size)
    else:
        node_trace['marker']['size'] = [1] * len(G.nodes())

    fig = Figure(
        data=Data([edge_trace, node_trace]),
        layout=Layout(
            title='<br>' + title,
            titlefont=dict(size=16),
            showlegend=False,
            width=1500,
            height=800,
            hovermode='closest',
            margin=dict(b=20, l=350, r=5, t=200),
            # family='Courier New, monospace', size=18, color='#7f7f7f',
            annotations=[
                dict(text="",
                     showarrow=False,
                     xref="paper",
                     yref="paper",
                     x=0.005,
                     y=-0.002)
            ],
            xaxis=XAxis(showgrid=False, zeroline=False, showticklabels=False),
            yaxis=YAxis(showgrid=False, zeroline=False, showticklabels=False)))

    offpy(fig, filename=filename, auto_open=True, show_link=False)
def visualize_graph_3d(G, node_labels, node_sizes, filename, title="3d"):
    edge_trace = Scatter3d(x=[],
                           y=[],
                           z=[],
                           mode='lines',
                           line=Line(color='rgba(136, 136, 136, .8)', width=1),
                           hoverinfo='none')

    node_trace = Scatter3d(
        x=[],
        y=[],
        z=[],
        mode='markers',
        #name='actors',
        marker=Marker(
            symbol='dot',
            size=[],
            color=[],
            colorscale='Jet',  #'Viridis',
            colorbar=dict(thickness=15,
                          title='Node Connections',
                          xanchor='left',
                          titleside='right'),
            line=Line(color='rgb(50,50,50)', width=0.5)),
        text=[],
        hoverinfo='text')

    positions = nx.fruchterman_reingold_layout(G,
                                               dim=3,
                                               k=0.5,
                                               iterations=1000)

    for edge in G.edges():
        x0, y0, z0 = positions[edge[0]]
        x1, y1, z1 = positions[edge[1]]
        edge_trace['x'] += [x0, x1, None]
        edge_trace['y'] += [y0, y1, None]
        edge_trace['z'] += [z0, z1, None]

    for node in G.nodes():
        x, y, z = positions[node]
        node_trace['x'].append(x)
        node_trace['y'].append(y)
        node_trace['z'].append(z)

    for adjacencies in G.adjacency_list():
        node_trace['marker']['color'].append(len(adjacencies))

    for size in node_sizes:
        node_trace['marker']['size'].append(size)

    for node in node_labels:
        node_trace['text'].append(node)

    axis = dict(showbackground=False,
                showline=False,
                zeroline=False,
                showgrid=False,
                showticklabels=False,
                title='')

    layout = Layout(
        title=title,
        width=1000,
        height=1000,
        showlegend=False,
        scene=Scene(
            xaxis=XAxis(axis),
            yaxis=YAxis(axis),
            zaxis=ZAxis(axis),
        ),
        margin=Margin(t=100),
        hovermode='closest',
        annotations=Annotations([
            Annotation(showarrow=False,
                       text="",
                       xref='paper',
                       yref='paper',
                       x=0,
                       y=0.1,
                       xanchor='left',
                       yanchor='bottom',
                       font=Font(size=14))
        ]),
    )

    data = Data([node_trace, edge_trace])
    fig = Figure(data=data, layout=layout)

    offpy(fig, filename=filename, auto_open=True, show_link=False)
Exemple #25
0
def visualize(config, G, node_size):
    keys = G.nodes()
    values = range(len(G.nodes()))
    dictionary = dict(zip(keys, values))
    inv_map = {v: k for k, v in dictionary.items()}
    G = nx.relabel_nodes(G, dictionary)
    try:
        pos = graphviz_layout(G)
    except:
        raise Exception("there is something wrong with graphviz")

    edge_trace = go.Scatter(x=[],
                            y=[],
                            line=dict(width=0.8,
                                      color='rgba(136, 136, 136, .9)'),
                            hoverinfo='none',
                            mode='lines')

    for edge in G.edges():
        x0, y0 = pos[edge[0]]
        x1, y1 = pos[edge[1]]
        edge_trace['x'] += (x0, x1, None)
        edge_trace['y'] += (y0, y1, None)

    # for weight in weights:
    #     print(weight)
    #     edge_trace['line']['width'].append(weight)

    node_trace = go.Scatter(
        x=[],
        y=[],
        text=[],
        mode='markers+text',
        textfont=dict(family='Calibri (Body)', size=14, color='black'),
        opacity=1,
        # hoverinfo='text',
        marker=go.Marker(
            showscale=True,
            # colorscale options
            # 'aggrnyl', 'agsunset', 'algae', 'amp', 'armyrose', 'balance',
            #              'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brbg',
            #              'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'curl',
            #              'darkmint', 'deep', 'delta', 'dense', 'earth', 'edge', 'electric',
            #              'emrld', 'fall', 'geyser', 'gnbu', 'gray', 'greens', 'greys',
            #              'haline', 'hot', 'hsv', 'ice', 'icefire', 'inferno', 'jet',
            #              'magenta', 'magma', 'matter', 'mint', 'mrybm', 'mygbm', 'oranges',
            #              'orrd', 'oryel', 'peach', 'phase', 'picnic', 'pinkyl', 'piyg',
            #              'plasma', 'plotly3', 'portland', 'prgn', 'pubu', 'pubugn', 'puor',
            #              'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu', 'rdgy',
            #              'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
            #              'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
            #              'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
            #              'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'
            colorscale=config.color_scale,
            reversescale=True,
            color=[],
            size=[],
            colorbar=dict(thickness=15,
                          title='Node Connections',
                          xanchor='left',
                          titleside='right'),
            line=dict(width=1.7)))

    for node in G.nodes():
        x, y = pos[node]
        node_trace['x'] += (x, )
        node_trace['y'] += (y, )

    for i, adjacencies in G.adjacency():
        node_trace['marker']['color'] += (len(adjacencies), )

    for node in G.nodes():
        node_trace['text'] += (inv_map[node], )

    for size in node_size:
        node_trace['marker']['size'] += (abs(math.log(size)) * 10, )

    fig = go.Figure(
        data=[edge_trace, node_trace],
        layout=go.Layout(
            title='<br>' + config.title,
            titlefont=dict(size=12),
            showlegend=False,
            width=1400,
            height=800,
            hovermode='closest',
            margin=dict(b=20, l=350, r=5, t=200),
            # family='Courier New, monospace', size=18, color='#7f7f7f',
            annotations=[
                dict(text="",
                     showarrow=False,
                     xref="paper",
                     yref="paper",
                     x=0.005,
                     y=-0.002)
            ],
            xaxis=go.layout.XAxis(showgrid=False,
                                  zeroline=False,
                                  showticklabels=False),
            yaxis=go.layout.YAxis(showgrid=False,
                                  zeroline=False,
                                  showticklabels=False)))

    offpy(fig, filename=config.out_file_name, auto_open=True, show_link=False)
Exemple #26
0
def visualize_3d(config, G, node_sizes):
    keys = G.nodes()
    values = range(len(G.nodes()))
    dictionary = dict(zip(keys, values))
    inv_map = {v: k for k, v in dictionary.items()}
    G = nx.relabel_nodes(G, dictionary)

    edge_trace = go.Scatter3d(x=[],
                              y=[],
                              z=[],
                              mode='lines',
                              line=go.scatter3d.Line(
                                  color='rgba(136, 136, 136, .8)', width=1),
                              hoverinfo='none')

    node_trace = go.Scatter3d(
        x=[],
        y=[],
        z=[],
        mode='markers',
        #name='actors',
        marker=go.scatter3d.Marker(
            symbol='circle',
            size=[],
            color=[],
            colorscale=config.color_scale,  #'Viridis',
            colorbar=dict(thickness=15,
                          title='Node Connections',
                          xanchor='left',
                          titleside='right'),
            #line=go.Line(color='rgb(50,50,50)', width=0.5)
        ),
        text=[],
        hoverinfo='text')

    positions = nx.fruchterman_reingold_layout(G,
                                               dim=3,
                                               k=0.5,
                                               iterations=1000)

    for edge in G.edges():
        x0, y0, z0 = positions[edge[0]]
        x1, y1, z1 = positions[edge[1]]
        edge_trace['x'] += (
            x0,
            x1,
        )
        edge_trace['y'] += (
            y0,
            y1,
        )
        edge_trace['z'] += (
            z0,
            z1,
        )

    for node in G.nodes():
        x, y, z = positions[node]
        node_trace['x'] += (x, )
        node_trace['y'] += (y, )
        node_trace['z'] += (z, )

    for i, adjacencies in G.adjacency():
        node_trace['marker']['color'] += (len(adjacencies), )

    for size in node_sizes:
        node_trace['marker']['size'] += (abs(math.log(size)) * 10, )

    for node in G.nodes():
        node_trace['text'] += (inv_map[node], )

    axis = dict(showbackground=False,
                showline=False,
                zeroline=False,
                showgrid=False,
                showticklabels=False,
                title='')

    layout = go.Layout(
        title=config.title,
        width=1000,
        height=1000,
        showlegend=False,
        scene=go.Scene(
            xaxis=go.XAxis(axis),
            yaxis=go.YAxis(axis),
            zaxis=go.ZAxis(axis),
        ),
        margin=go.Margin(t=100),
        hovermode='closest',
    )

    fig = go.Figure(data=[node_trace, edge_trace], layout=layout)

    offpy(fig, filename=config.out_file_name, auto_open=True, show_link=False)
Exemple #27
0
import plotly.plotly as py
from plotly.offline import iplot, plot as offpy
fig = py.get_figure('https://plot.ly/~jackp/8715', raw=True)
iplot(fig)
print(offpy(fig, filename='33.html', auto_open=True, show_link=False))
Exemple #28
0
from plotly.offline import plot as offpy
import plotly.graph_objs as go
trace = go.Heatmap(
    name='1st Trace',
    z=[1, 2, 3],
    x=[4, 5, 6],
    y=[7, 8, 9],
    colorscale='Jet',
)
data = [trace]
layout = dict(title='asdasdasdasd',
              yaxis=dict(title='yyyyyyyy', tickmode="array"),
              xaxis=dict(title='xxxxxxxxxxxx', tickmode="array"))
fig = go.Figure(data=data, layout=layout)
offpy(fig,
      show_link=False,
      include_plotlyjs=True,
      filename='d3-world-map.html')
#
#
# import plotly.figure_factory as ff
# df = pd.read_excel("1.xlsx", names = ['Country', 'Share'],skiprows = [0])
# df['Share'] = pd.Series(["{0:.1}%".format(val * 100) for val in df['Share']], index = df.index)
# data = [ dict(
#         type = 'choropleth',
#         locations = df['Country'],
#         z = df['Share'],
#         text = df['Country'],
#         colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\
#             [0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
#         autocolorscale = False,
#         reversescale = True,
Exemple #29
0
def visualize_associations(X, Y, Z, output_file):
    trace = go.Heatmap(z=Z, x=X, y=Y)
    data = [trace]
    fig = go.Figure(data=data)
    offpy(fig, filename=output_file + ".html", auto_open=True, show_link=False)
Exemple #30
0
def bar_chart_plot(x, y, output_file):
    data = [go.Bar(x=x, y=y)]

    fig = go.Figure(data=data)

    offpy(fig, filename=output_file + ".html", auto_open=True, show_link=False)