How to use the mpld3.plugins.LineLabelTooltip 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 tim-fiola / network_traffic_modeler_py3 / examples / graph_network / graph_network_interactive.py View on Github external
color='r', alpha=0.7, markersize=15,
                                markeredgewidth=1)

        # Plot the line
        line = ax.plot(x_coordinates, y_coordinates, color=link['color'],
                       linewidth=5.0, label=link['color'])

        # Need to normalize some stuff for the line labels for the line tooltips
        link_source = _find_link_source_node(link)

        line_labels = ['from-' + link['target'] + '-to-' + link_source + '; \
                            utilization = ' + link['utilization']]

        # Add the tooltip labels to lines.
        # Notice we use the *LineLabelTooltip
        mpld3.plugins.connect(fig, mpld3.plugins.LineLabelTooltip(line[0], label=line_labels))

        # Drag plugin for nodes
        mpld3.plugins.connect(fig, LinkedDragPlugin(nodes_on_plot[0], line[0]))

        # Add the tooltip node labels
        # Notice we use the *PointLabelTooltip
        mpld3.plugins.connect(fig, mpld3.plugins.PointLabelTooltip(nodes_on_plot[0], labels=node_tool_tip_labels))

    # Plot the midpoint node labels
    for node in (node for node in json_data['nodes'] if 'midpoint' in node['id']):
        x, y = node['pos'][1], node['pos'][0]
        text = node['name']
        ax.text(x, y, text, fontsize=10, color='k', fontname='monospace')

    # Plot the router node labels
    for node in (node for node in json_data['nodes'] if 'midpoint' not in node['id']):
github hugadams / scikit-spectra / skspec / interact / ipynbs / specgram.py View on Github external
norm=self.NORMUNITS_REV[self.norm_unit],
                                    **colorkwags
                                    )
            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 hugadams / scikit-spectra / skspec / plotting / mpld3wrapper.py View on Github external
""" Wrappers and utilitiles for MPLD3 customization """

import mpld3
from mpld3.plugins import Reset, Zoom, BoxZoom, \
           PointLabelTooltip, PointHTMLTooltip, LineLabelTooltip, \
           MousePosition, LineHTMLTooltip

ALLPLUGINS = dict(
   reset=Reset,
   zoom=Zoom,
   boxzoom=BoxZoom, 
   pointlabel=PointLabelTooltip,
   pointHTMLlabel = PointHTMLTooltip, 
   linelabel=LineLabelTooltip, 
   linehtml=LineHTMLTooltip,
   mousepos=MousePosition
   )

# Reversed dictionary
ALLPLUGINS_REV = dict((v, k) for k,v in ALLPLUGINS.items())

# Plugins that require access to lines
LABELPLUGINS = [LineLabelTooltip, PointLabelTooltip]
HTMLPLUGINS = [LineHTMLTooltip, PointHTMLTooltip]

DEFAULTS = ('reset','boxzoom','zoom')

class PluginManagerError(Exception):
   """ """
github hugadams / scikit-spectra / skspec / plotting / mpld3wrapper.py View on Github external
ALLPLUGINS = dict(
   reset=Reset,
   zoom=Zoom,
   boxzoom=BoxZoom, 
   pointlabel=PointLabelTooltip,
   pointHTMLlabel = PointHTMLTooltip, 
   linelabel=LineLabelTooltip, 
   linehtml=LineHTMLTooltip,
   mousepos=MousePosition
   )

# Reversed dictionary
ALLPLUGINS_REV = dict((v, k) for k,v in ALLPLUGINS.items())

# Plugins that require access to lines
LABELPLUGINS = [LineLabelTooltip, PointLabelTooltip]
HTMLPLUGINS = [LineHTMLTooltip, PointHTMLTooltip]

DEFAULTS = ('reset','boxzoom','zoom')

class PluginManagerError(Exception):
   """ """

class PluginManager(object):
   """ Wrapper for adding/removing/printing plugins available on a 
   mplfigure.  Returns a figure (via self.fig) with seleted plugins attached.
   Used primarily for widgets/guis where the state of plugins
   needs managed.  Otherwise, using MPLD3 API directly with a mpl figure
   is simple and preferred.
   """
   
   def __init__(self, fig, ax=None, names=None):
github interrogator / corpkit / corpkit / plotter.py View on Github external
plugins.connect(plt.gcf(), HighlightLines(lines))

        if 3 in interactive_types:
            plugins.connect(plt.gcf(), InteractiveLegendPlugin(lines, labels, alpha_unsel=0.0))

        for i, l in enumerate(lines):
            y_vals = l.get_ydata()
            x_vals = l.get_xdata()
            x_vals = [str(x) for x in x_vals]
            if absolutes:
                ls = ['%s (%s: %d)' % (labels[i], x_val, y_val) for x_val, y_val in zip(x_vals, y_vals)]
            else:
                ls = ['%s (%s: %.2f%%)' % (labels[i], x_val, y_val) for x_val, y_val in zip(x_vals, y_vals)]
            if 2 in interactive_types:
                #if 'kind' in kwargs and kwargs['kind'] == 'area':
                tooltip_line = mpld3.plugins.LineLabelTooltip(lines[i], labels[i])
                mpld3.plugins.connect(plt.gcf(), tooltip_line)
                #else:
                if kind == 'line':
                    tooltip_point = mpld3.plugins.PointLabelTooltip(l, labels = ls)
                    mpld3.plugins.connect(plt.gcf(), tooltip_point)
        
    if piemode:
        if not sbplt:
            plt.axis('equal')
            ax.get_xaxis().set_visible(False)
            ax.get_yaxis().set_visible(False)

    # add x label
    # this could be revised now!
    # if time series period, it's year for now
    if isinstance(dataframe.index, pandas.tseries.period.PeriodIndex):