How to use the mpld3.plugins 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 HybriD3-database / MatD3 / materials / plotting / pl_plotting.py View on Github external
# print(x[min_index])
    # Xlim = maxXlim - minXlim
    # ax.axhline(y=1, xmin=(x[peak_index]-minXlim)/Xlim, ls='--', color='r')
    # ax.axhline(y=0, xmin=(x[min_index]-minXlim)/Xlim, ls='--', color='r')

    # print points[0]
    labels = []
    for i,j in zip(x,y):
        label = '<div class="tooltiptext">'
        label += '{2}: {1} <br> {3}: {0}'.format(i, j, y_label, x_label)
        label += '</div>'
        labels.append(label)

    tooltip = plugins.PointHTMLTooltip(points[0], labels, hoffset=-tooltipwidth/2, voffset=-tooltipheight, css=css)

    plugins.connect(fig, tooltip)

    save_name = "{}.html".format(filename.split(".")[0])
    # filename = "{}.png".format(filename.split(".")[0])
    # plt.savefig(filename, dpi = 300, bbox_inches='tight')
    mpld3.save_html(fig, save_name)
    plt.close()
    # mpld3.fig_to_html(plt_figure)
github hugadams / scikit-spectra / skspec / interact / ipynbs / specgram.py View on Github external
)
            f.tight_layout() #Padding around plot
            lines = ax.get_lines()
            plt.close(f)
                                    
            #http://mpld3.github.io/modules/API.html
            if self.interactive:
                import mpld3
                if self.selectlines:
                    from line_plugin import HighlightLines
                    
                    for idx, col in enumerate(self.spec_modified.columns):
                        name = 'COLUMN(%s): %s' % (idx, col)
                        tooltip = mpld3.plugins.LineLabelTooltip(lines[idx], name)
                        #voffset=10, hoffset=10,  css=css)
                        mpld3.plugins.connect(f, tooltip)
                    
                    mpld3.plugins.connect(f, HighlightLines(lines))
                
                plot_and_message += mpld3.fig_to_html(f)
            else:
                plot_and_message += mpl2html(f)
            
            self.fig_old = f
        
        else:
            plot_and_message += html_figure(self.fig_old)
        
        # VALUE IS WHAT GUI LOOKS UP!!!
        self.value = plot_and_message
github dparks1134 / RefineM / refinem / plots / gc_cov_plot.py View on Github external
# scatterplot
        xlabel = 'GC (mean = %.1f%%)' % mean_gc
        ylabel = 'Coverage (mean = %.1f)' % mean(mean_coverage)

        scatter, x_pts, y_pts, labels = self.scatter(axis, 
                                                        pts,
                                                        highlight_scaffold_ids, 
                                                        link_scaffold_ids,
                                                        xlabel, 
                                                        ylabel)

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

        return scatter, x_pts, y_pts, self.plot_order(labels)
github Project-Platypus / PRIM / prim / prim_box.py View on Github external
text-align: right;
            }
            """   
            
            labels = []
            columns_to_include = ['coverage','density', 'mass', 'res dim']
            frmt = lambda x: '{:.2f}'.format( x )
            
            for i in range(len(self.peeling_trajectory['coverage'])):
                label = self.peeling_trajectory.ix[[i], columns_to_include]
                label.columns = ["Coverage", "Density", "Mass", "Res. Dim."]
                label = label.T
                label.columns = ["Box {0}".format(i)]
                labels.append(str(label.to_html(float_format=frmt)))       
    
            tooltip = mpld3.plugins.PointHTMLTooltip(p, labels, voffset=10, 
                                                     hoffset=10, css=css)  
            mpld3.plugins.connect(fig, tooltip)        
        
        return fig
github flairNLP / flair / flair / visual / manifold.py View on Github external
import matplotlib.pyplot
        import mpld3

        fig, ax = matplotlib.pyplot.subplots()

        ax.grid(True, alpha=0.3)

        points = ax.plot(
            X[:, 0], X[:, 1], "o", color="b", mec="k", ms=5, mew=1, alpha=0.6
        )

        ax.set_xlabel("x")
        ax.set_ylabel("y")
        ax.set_title("Hover mouse to reveal context", size=20)

        tooltip = mpld3.plugins.PointHTMLTooltip(
            points[0], contexts, voffset=10, hoffset=10
        )

        mpld3.plugins.connect(fig, tooltip)

        mpld3.save_html(fig, file)
github automl / CAVE / spysmac / plot / confs_viz / viz_sampled_confs.py View on Github external
# # Show only desired run
        # handles, labels = ax.get_legend_handles_labels() # return lines and labels
        # self.logger.debug("Handles: %s", handles)
        # self.logger.debug("Labels: %s", labels)
        # interactive_legend = mpld3.plugins.InteractiveLegendPlugin(zip(handles,
        #                                                          ax.collections),
        #                                                      labels,
        #                                                      alpha_unsel=0,
        #                                                      alpha_over=1,
        #                                                      start_visible=True)
        # mpld3.plugins.connect(fig, interactive_legend)

        tooltip = mpld3.plugins.PointHTMLTooltip(scatter, labels,
                                                 voffset=10, hoffset=10)#, css=self.css)

        mpld3.plugins.connect(fig, tooltip)

        if scatter_inc:
            tooltip = mpld3.plugins.PointHTMLTooltip(scatter_inc, np.array(labels)[inc_indx].tolist(),
                                                     voffset=10, hoffset=10)#, css=self.css)

        mpld3.plugins.connect(fig, tooltip)

        if self.output_dir:
            self.logger.debug("Save to %s", self.output_dir)
            with open(self.output_dir, "w") as fp:
                mpld3.save_html(fig, fp)

        html = mpld3.fig_to_html(fig)
        plt.close(fig)
        return html
github AlJohri / OpenSubtitles / analyze.py View on Github external
ax = fig.add_subplot(1,N_CLUSTERS+1,1)
    ax.grid(True, alpha=0.3)

    colors = [(random.random(), random.random(), random.random()) for x in range(N_CLUSTERS)]
    for k, col in zip(range(N_CLUSTERS), colors):
        my_members = k_means_labels == k
        cluster_center = k_means_cluster_centers[k]
        points = ax.plot(X[my_members, 0], X[my_members, 1], 'w', markerfacecolor=col, marker='.', label='Cluster %i' % k)
        centers = ax.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor=col, markeredgecolor='k', markersize=6)
        
        labels = []
        for movie in movies[k_means_labels == k]:
            labels.append(movie.get('Title', '') + " " + movie.get('imdbID', '') + " " + ", ".join(movie.get('Genre', '')) + " " + movie.get('', '') + " ")

        tooltip = plugins.PointHTMLTooltip(points[0], labels, voffset=10, hoffset=10)
        plugins.connect(fig, tooltip)

    ax.set_title('KMeans')
    ax.set_xticks(())
    ax.set_yticks(())
    ax.legend()

    blah = []

    for k in range(N_CLUSTERS):

        innerDict = {}

        for movie in movies[k_means_labels == k]:
            genres = movie.get('Genre', '')
            for genre in genres:
                if genre in innerDict:
github Project-Platypus / PRIM / ema_workbench / prim.py View on Github external
text-align: right;
            }
            """   
            
            labels = []
            columns_to_include = ['coverage','density', 'mass', 'res dim']
            frmt = lambda x: '{:.2f}'.format( x )
            for i in range(len(self.peeling_trajectory['coverage'])):
                label = self.peeling_trajectory.ix[[i], columns_to_include].T
                label.columns = ['box {0}'.format(i)]
                # .to_html() is unicode; so make leading 'u' go away with str()
                labels.append(str(label.to_html(float_format=frmt)))        
    
            tooltip = mpld3.plugins.PointHTMLTooltip(p, labels, voffset=10, 
                                               hoffset=10, css=css)  
            mpld3.plugins.connect(fig, tooltip)        
        
        return fig