How to use the mpld3.plugins.connect function in mpld3

To help you get started, we’ve selected a few mpld3 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 svenkreiss / databench_examples / analyses / mpld3PointLabel / analysis.py View on Github external
def on_connect(self):
        """Run as soon as a browser connects to this."""

        fig, ax = plt.subplots()
        points = ax.scatter(
            np.random.rand(40),
            np.random.rand(40),
            s=300,
            alpha=0.3,
        )

        # use the mpld3 tooltop plugin
        labels = ["Point {0}".format(i) for i in range(40)]
        tooltip = mpld3.plugins.PointLabelTooltip(points, labels)
        mpld3.plugins.connect(fig, tooltip)

        # send the plot to the frontend
        self.emit('mpld3canvas', mpld3.fig_to_dict(fig))

        # done
        self.emit('log', {'action': 'done'})
github tim-fiola / network_traffic_modeler_py3 / examples / graph_network / graph_network_interactive.py View on Github external
if node['failed'] is False:
            text = node['name']
        else:
            text = node['name'] + ' (failed)'
        ax.text(x, y, text, fontsize=15, color='k', fontname='monospace')

    # Create interactive legend
    line_collections, line_group_labels = _create_legend_line_collections(ax)

    interactive_legend = plugins.InteractiveLegendPlugin(line_collections,
                                                         line_group_labels,
                                                         alpha_unsel=0.2,
                                                         alpha_over=1.8,
                                                         start_visible=True)
    fig.subplots_adjust(right=0.85)
    plugins.connect(fig, interactive_legend)

    time_now = str(time.asctime())
    ax.set_title("Network Graph:" + time_now, size=15)

    plot_thread = threading.Thread(target=_run_plot)
    plot_thread.start()
github salilab / imp / modules / pmi / pyext / src / io / xltable.py View on Github external
df = pd.DataFrame(index=xl_labels)

        sorted_keys=sorted(xl_list[0].keys())

        for k in sorted_keys:
            df[k] = np.array([xl[k] for xl in xl_list])

        labels = []
        for i in range(len(xl_labels)):
            label = df.ix[[i], :].T
            # .to_html() is unicode; so make leading 'u' go away with str()
            labels.append(str(label.to_html()))

        tooltip = plugins.PointHTMLTooltip(points, labels,
                                   voffset=10, hoffset=10, css=css)
        plugins.connect(fig, tooltip)
        mpld3.save_html(fig,"output.html")
github Patent2net / P2N / Patent2Net / P2N-Cluster.py View on Github external
mpld3.plugins.connect(fig,interactive_legend)
mpld3.plugins.connect(fig,interactive_legend2)   

tooltip =dict()
for ligne in fig.get_axes()[0].lines:
        Urls=[]
        labels =[]
        for point in ligne.get_xydata():
            if tuple(point) in MemoPoints.keys():
                Urls.append('file:///'+ Here +Tit2FicName [MemoPoints[tuple(point)]])
                labels.append(MemoPoints[tuple(point)])
            else:
                print("should never be here")
        mpld3.plugins.connect(fig, ClickInfo( ligne, labels=labels,  urls = Urls))
 
mpld3.plugins.connect(fig, TopToolbar())

from pandas.plotting import scatter_matrix
ptl = scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')


#uncomment the below to export to html
html = mpld3.fig_to_html(fig)

with open(ResultPath+"//"+ndf+"-Clust.html", "w") as fic:
    fic.write(html)
github dparks1134 / RefineM / refinem / plots / gc_plots.py View on Github external
xL = np.array(xL)[sort_indexY]
            xU = np.array(xU)[sort_indexY]
            y = np.array(y)[sort_indexY]
            axes_scatter.plot(xL, y, 'r--', lw=1.0, zorder=0)
            axes_scatter.plot(xU, y, 'r--', lw=1.0, zorder=0)

        # ensure y-axis include zero and covers all sequences
        axes_scatter.set_ylim([0, ymax])

        # ensure x-axis is set appropriately for sequences
        axes_scatter.set_xlim([xmin, xmax])

        # tooltips plugin
        if tooltip_plugin:
            tooltip = Tooltip(scatter, labels=plot_labels, hoffset=5, voffset=-15)
            mpld3.plugins.connect(figure, tooltip)

        return scatter, x_pts, y_pts, self.plot_order(plot_labels)
github sglebs / srccheck / utilities / utils.py View on Github external
def save_scatter(x_values, x_label, y_values, y_label, ball_values, ball_label, color_values, color_label, annotations, filename_prefix, scope_name, show_diagonal=False, format="html"):
    #plt.figure()  # new one, or they will be mixed
    fig, ax = plt.subplots()
    plt.xlabel(x_label)
    plt.ylabel(y_label)
    plt.title("%i %s items. Circles: %s & %s" % (len(x_values), scope_name, ball_label, color_label))
    if show_diagonal:
        max_max = max(max(x_values), max(y_values))
        ax.plot([0.0, max_max], [0.0, max_max], ls="--", lw=2, alpha=0.5,
                color='green')  # http://matplotlib.org/api/lines_api.html
    scatter = ax.scatter(x_values, y_values, ball_values, alpha=0.5, c=color_values)
    filename = "%s-scatter-%s-%s_%s_%s.%s" % (filename_prefix, scope_name, x_label, y_label, ball_label, format)
    if format == "html":
        tooltip = mpld3.plugins.PointHTMLTooltip(scatter, labels=annotations, hoffset=10, voffset=-25)
        mpld3.plugins.connect(fig, tooltip)
        mpld3.plugins.connect(fig, mpld3.plugins.MousePosition(fmt=".2f"))
        mpld3.plugins.connect(fig, ClickSendToBack(scatter))
        _save_figure_as_html(fig, filename)
    else:
        plt.savefig(filename, dpi=72)
    return filename
github ijmarshall / robotreviewer3 / robotreviewer / robots / pico_viz_robot.py View on Github external
for i, element in enumerate(self.elements):
            X_hat = self.PCA_dict[element].transform(embeddings_dict[element])

            cur_ax = axes_array[i]

            points, RGB_palette = scatter(study_names, X_hat, cur_ax, title=element.lower())

            # setup labels; color code consisent w/scatter
            labels = []
            for study_idx, study_words in enumerate(words_dict[element]):
                label_str = u"<p style="color:{0}">".format(RGB_palette[study_idx])
                label_str +=  ", ".join(study_words) + "</p>"
                labels.append(label_str)

            tooltip = mpld3.plugins.PointHTMLTooltip(points, labels=labels)
            mpld3.plugins.connect(f, tooltip)

        return mpld3.fig_to_html(f)