How to use the mpld3.plugins.PointHTMLTooltip 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[peak_index])
    # print(maxXlim)
    # 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 stripe / topmodel / topmodel / plot_helpers.py View on Github external
fig1, ax1 = plt.subplots()
    if fig is None:
        fig = fig1
    if ax is None:
        ax = ax1
    for i in range(1, len(xs)):
        ax.plot(xs[i], ys[i], '-', alpha=0.3)
    (xs_, ys_, thresholds_) = make_points_far(xs[0], ys[0], thresholds)
    label_text = ["Threshold: %s (%s, %s)" % (t, pretty_point(x), pretty_point(y))
                  for (x, y, t) in zip(xs_, ys_, thresholds_)]
    if label is None:
        scatter = ax.plot(xs_, ys_, '-o', **plot_kwargs)
        plugins.connect(fig, plugins.PointHTMLTooltip(scatter[0], label_text))
    else:
        scatter = ax.plot(xs_, ys_, '-o', label=label, **plot_kwargs)
        plugins.connect(fig, plugins.PointHTMLTooltip(scatter[0], label_text))
    if labels:
        draw_labels(ax, xs_, ys_, thresholds_, labels_left=labels_left)
    plt.xlim(0, 1)
    plt.ylim(0, 1)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.tight_layout()
    if label is not None:
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles[::-1], labels[::-1], loc='best')
    return save_image()
github automl / CAVE / spysmac / plot / confs_viz / viz_sampled_confs.py View on Github external
# 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 stanfordnlp / cocoa / craigslistbargain / analysis / dialogue.py View on Github external
# Draw stage boundary
        for b in stage_boundary:
            vline(ax, (b-0.5), y_min, y_max, 'k-')
        # Draw target prices
        N = len(data['time_step'])
        for kb in self.kbs:
            target = kb.facts['personal']['Target']
            hline(ax, target, 0, N+1, 'r--')

        # Scatter seller points
        for role, color in izip(('seller', 'buyer'), ('r', 'b')):
            time_step = [x for x, r in izip(data['time_step'], data['role']) if r == role]
            price = [x for x, r in izip(data['price'], data['role']) if r == role]
            points = ax.scatter(time_step, price, s=200, zorder=20)
            labels = ['<div class="utterance">{}</div>'.format(u) for u, r in izip(data['text'], data['role']) if r == role]
            tooltip = mpld3.plugins.PointHTMLTooltip(points, labels=labels, voffset=10, hoffset=10, css=self.css)
            mpld3.plugins.connect(fig, tooltip)

        fig_dict = mpld3.fig_to_dict(fig)
        plt.close()
        return fig_dict
github Liu3420175 / flask_web / app / admin / statistics.py View on Github external
label1 = df1.ix[[i], :].T
        label1.columns = ['{0}'.format(x1[i])]
        labels1.append(str(label1.to_html()))

    # 配置时间坐标
    plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
    plt.gca().xaxis.set_major_locator(mdates.DayLocator())

    fig, ax = plt.subplots()
    points = ax.plot(x,y, '-or',label=_label[0])#TODO 画折线图,实线,红色,标记标点
    points1 = ax.plot(x1,y1,'-ob',label=_label[1])
    plt.gcf().autofmt_xdate()
    plt.legend(loc='upper right')#制定图例标注

    interactive_legend = plugins.PointHTMLTooltip(points[0],labels,css=css)
    interactive_legend1 = plugins.PointHTMLTooltip(points1[0],labels1,css=css)
    ax.set_xlabel('日期')
    ax.set_ylabel('数量')
    title = "{0}数量趋势".format(title)
    ax.set_title(title, size=20)

    plugins.connect(fig, interactive_legend,interactive_legend1)
    #plugins.connect(fig,interactive_legend1)

    html_data = mpld3.fig_to_html(fig)
    return html_data
github automl / CAVE / spysmac / plot / confs_viz / viz_sampled_confs.py View on Github external
#fig.savefig("test.png")

        # WORK IN PROGRESS
        # # 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)
github JasonKessler / scattertext / build / lib / texttoideas / RudderChart.py View on Github external
| df['term'].isin(words_to_annotate)]
		words = list(df['term'])

		fig, ax = plt.subplots()
		plt.figure(figsize=(10, 10))
		plt.gcf().subplots_adjust(bottom=0.2)
		plt.gcf().subplots_adjust(right=0.2)

		points = ax.scatter(x_data,
		                    y_data,
		                    c=-df['color_scores'],
		                    cmap='seismic',
		                    s=10,
		                    edgecolors='none',
		                    alpha=0.9)
		tooltip = plugins.PointHTMLTooltip(points,
		                                   ['<span id="a">%s</span>' % w for w in words],
		                                   css='#a {background-color: white;}')
		plugins.connect(fig, tooltip)
		ax.set_ylim([-.2, 1.2])
		ax.set_xlim([-.2, 1.2])
		ax.xaxis.set_ticks([0., 0.5, 1.])
		ax.yaxis.set_ticks([0., 0.5, 1.])
		ax.set_ylabel(category.title() + ' Frequency Percentile', fontdict=font, labelpad=20)
		ax.set_xlabel('Not ' + category.title() + ' Frequency Percentile', fontdict=font, labelpad=20)

		for i, row in df_to_annotate.iterrows():
			# alignment_criteria = row['category score rank'] &lt; row['not category score rank']
			alignment_criteria = i % 2 == 0
			horizontalalignment = 'right' if alignment_criteria else 'left'
			verticalalignment = 'bottom' if alignment_criteria else 'top'
			term = row['term']
github Project-Platypus / PRIM / ema_workbench / prim.py View on Github external
font-size: 16px;
              border: 1px solid black;
              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