How to use the mpld3.plugins.MousePosition 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 kjyv / FloBaRoID / identification / output.py View on Github external
if idf.opt['outputAs'] == 'html':
                    #TODO: show legend properly (see mpld3 bug #274)
                    #leg = fig.legend(handles, labels, loc='upper right', fancybox=True, fontsize=10, title='')
                    leg = axes[0].legend(handles, labels, loc='upper right', fancybox=True, fontsize=10, title='', prop={'size': 8})
                else:
                    leg = plt.figlegend(handles, labels, loc='upper right', fancybox=True,
                            fontsize=font_size, title='', prop={'size': font_size-3})
                    leg.draggable()

            fig.subplots_adjust(hspace=2)
            fig.set_tight_layout(True)

            if idf.opt['outputAs'] == 'html':
                plugins.clear(fig)
                plugins.connect(fig, plugins.Reset(), plugins.BoxZoom(), plugins.Zoom(enabled=False),
                                plugins.MousePosition(fontsize=14, fmt=".5g"))
                figures.append(mpld3.fig_to_html(fig))
            elif idf.opt['outputAs'] == 'interactive':
                plt.show(block=False)
            elif idf.opt['outputAs'] == 'pdf':
                pp.savefig(plt.gcf())
            elif idf.opt['outputAs'] == 'tikz':
                from matplotlib2tikz import save as tikz_save
                tikz_save('{}_{}_{}.tex'.format(filename,
                    group['dataset'][0]['title'].replace('_','-'), ds // idf.model.num_dofs),
                    figureheight = '\\figureheight', figurewidth = '\\figurewidth', show_info=False)

        if idf.opt['outputAs'] == 'html':
            path = os.path.dirname(os.path.abspath(__file__))
            template_environment = Environment(autoescape=False,
                                               loader=FileSystemLoader(os.path.join(path, '../output')),
                                               trim_blocks=False)
github sglebs / srccheck / utilities / utils.py View on Github external
if show_diagonal:
        plt.plot([0.0, 1.0], [1.0, 0.0], 'k-', ls="--", lw=2, alpha=0.5, color='green') # http://matplotlib.org/api/lines_api.html

        plt.plot([0.0, 0.7], [0.7, 0.0], 'k-', ls="--", lw=1, alpha=0.7, color='orange')  # http://matplotlib.org/api/lines_api.html
        plt.plot([0.3, 1.0], [1.0, 0.3], 'k-', ls="--", lw=1, alpha=0.7, color='orange')  # http://matplotlib.org/api/lines_api.html

        plt.plot([0.0, 0.4], [0.4, 0.0], 'k-', ls="--", lw=1, alpha=0.9, color='red')  # http://matplotlib.org/api/lines_api.html
        plt.plot([0.6, 1.0], [1.0, 0.6], 'k-', ls="--", lw=1, alpha=0.9, color='red')  # http://matplotlib.org/api/lines_api.html

    scatter = ax.scatter(x_values, y_values, ball_values, alpha=0.5, c=color_values)
    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))
    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))
    filename = "%s-scatter-%s-%s_%s_%s.html" % (filename_prefix, scope_name, x_label, y_label, ball_label)
    _save_figure_as_html(fig, filename)
    return filename
github HybriD3-database / MatD3 / materials / plotting / example.py View on Github external
x = np.linspace(-2, 2, 20)
y = x[:, None]
X = np.zeros((20, 20, 4))

X[:, :, 0] = np.exp(- (x - 1) ** 2 - (y) ** 2)
X[:, :, 1] = np.exp(- (x + 0.71) ** 2 - (y - 0.71) ** 2)
X[:, :, 2] = np.exp(- (x + 0.71) ** 2 - (y + 0.71) ** 2)
X[:, :, 3] = np.exp(-0.25 * (x ** 2 + y ** 2))

im = ax.imshow(X, extent=(10, 20, 10, 20),
               origin='lower', zorder=1, interpolation='nearest')
fig.colorbar(im, ax=ax)

ax.set_title('An Image', size=20)

plugins.connect(fig, plugins.MousePosition(fontsize=14))

# mpld3.show()
mpld3.save_html(fig, "test.html")
github dparks1134 / RefineM / refinem / plots / combined_plots.py View on Github external
td_dist : d[length][percentile] -> critical value
          TD distribution.
        gc_perc : float
          GC percentile value to mark on plot.
        td_perc : float
          TD percentile value to mark on plot.
        cov_perc : float
            Mean percent deviation to mark on plot.
        """

        # Set size of figure
        self.fig.clear()

        mpld3.plugins.clear(self.fig)
        mpld3.plugins.connect(self.fig, mpld3.plugins.Reset(), mpld3.plugins.BoxZoom(), mpld3.plugins.Zoom())
        mpld3.plugins.connect(self.fig, mpld3.plugins.MousePosition(fontsize=12, fmt='.1f'))

        self.fig.set_size_inches(self.options.width, self.options.height)
        
        # create subplots depending on availability of coverage information
        if len(genome_stats.mean_coverage) >= 1:
            # note: the ordering here is specific and ensures
            # proper linked brushing
            axes_gc_dist = self.fig.add_subplot(241)
            axes_tetra_dist = self.fig.add_subplot(242)
            axes_coverage_dist = self.fig.add_subplot(243)
            axes_td_cov = self.fig.add_subplot(246)
            axes_pc1_cov = self.fig.add_subplot(247)
            axes_tetra_pc1_pc3 = self.fig.add_subplot(248)  
            axes_gc_coverage = self.fig.add_subplot(245)
            axes_tetra_pc1_pc2 = self.fig.add_subplot(244)            
        else:
github dparks1134 / RefineM / refinem / plots / tetra_pca_plot.py View on Github external
Parameters
        ----------
        genome_scaffold_stats : d[scaffold_id] -> namedtuple of scaffold stats
          Statistics for scaffolds in genome.
        highlight_scaffold_ids : d[scaffold_id] -> color
            Scaffolds in genome to highlight.
        link_scaffold_ids : list of scaffold pairs
            Pairs of scaffolds to link together.
        """

        # Set size of figure
        self.fig.clear()

        mpld3.plugins.clear(self.fig)
        mpld3.plugins.connect(self.fig, mpld3.plugins.Reset(), mpld3.plugins.BoxZoom(), mpld3.plugins.Zoom())
        mpld3.plugins.connect(self.fig, mpld3.plugins.MousePosition(fontsize=12, fmt='.1f'))

        self.fig.set_size_inches(self.options.width, self.options.height)

        axis_pc1_pc2 = self.fig.add_subplot(221)
        axis_pc3_pc2 = self.fig.add_subplot(222)
        axis_pc1_pc3 = self.fig.add_subplot(223)
        axis_variance = self.fig.add_subplot(224)

        scatter, _, _, _ = self.plot_on_axes(self.fig, 0, 1,
                                              genome_scaffold_stats,
                                              highlight_scaffold_ids,
                                              link_scaffold_ids,
                                              axis_pc1_pc2, True)

        self.plot_on_axes(self.fig, 2, 1,
                          genome_scaffold_stats,
github dparks1134 / RefineM / refinem / plots / gc_cov_plot.py View on Github external
highlight_scaffold_ids : d[scaffold_id] -> color
          Scaffolds in genome to highlight.
        link_scaffold_ids : list of scaffold pairs
          Pairs of scaffolds to link together.
        mean_gc : float
          Mean GC of genome.
        mean_coverage : list of float
          Mean coverage profile of genome.
        """

        # Set size of figure
        self.fig.clear()

        mpld3.plugins.clear(self.fig)
        mpld3.plugins.connect(self.fig, mpld3.plugins.Reset(), mpld3.plugins.BoxZoom(), mpld3.plugins.Zoom())
        mpld3.plugins.connect(self.fig, mpld3.plugins.MousePosition(fontsize=12, fmt='.1f'))

        self.fig.set_size_inches(self.options.width, self.options.height)

        axis = self.fig.add_subplot(111)

        scatter, _, _,  _ = self.plot_on_axes(self.fig, genome_scaffold_stats,
                                                highlight_scaffold_ids, link_scaffold_ids,
                                                mean_gc, mean_coverage,
                                                axis, True)
                                                  
        mpld3.plugins.connect(self.fig, LinkedBrush(scatter))

        self.fig.tight_layout(pad=1, w_pad=1)
        self.draw()
github dparks1134 / RefineM / refinem / plots / td_plots.py View on Github external
link_scaffold_ids : list of scaffold pairs
            Pairs of scaffolds to link together.
        mean_signature : float
          Mean tetranucleotide signature of genome.
        td_dist : d[length][percentile] -> critical value
          TD distribution.
        percentiles_to_plot : iterable
          Percentile values to mark on plot.
        """

        # Set size of figure
        self.fig.clear()

        mpld3.plugins.clear(self.fig)
        mpld3.plugins.connect(self.fig, mpld3.plugins.Reset(), mpld3.plugins.BoxZoom(), mpld3.plugins.Zoom())
        mpld3.plugins.connect(self.fig, mpld3.plugins.MousePosition(fontsize=12, fmt='.1f'))

        self.fig.set_size_inches(self.options.width, self.options.height)

        axes_hist = self.fig.add_subplot(121)
        axes_scatter = self.fig.add_subplot(122)

        self.plot_on_axes(self.fig,
                          genome_scaffold_stats,
                          highlight_scaffold_ids,
                          link_scaffold_ids,
                          mean_signature, td_dist, percentiles_to_plot,
                          axes_hist, axes_scatter, True)

        self.fig.tight_layout(pad=1, w_pad=1)
        self.draw()
github gwastro / pycbc / pycbc / results / followup.py View on Github external
def trigger_timeseries_plot(file_list, ifos, start, end):

    fig = pylab.figure()
    for ifo in ifos:
        trigs = columns_from_file_list(file_list,
                                       ['snr', 'end_time'],
                                       ifo, start, end)
        print(trigs)
        pylab.scatter(trigs['end_time'], trigs['snr'], label=ifo,
                      color=ifo_color[ifo])

        fmt = '.12g'
        mpld3.plugins.connect(fig, mpld3.plugins.MousePosition(fmt=fmt))
    pylab.legend()
    pylab.xlabel('Time (s)')
    pylab.ylabel('SNR')
    pylab.grid()
    return mpld3.fig_to_html(fig)