def _determine_mpld4ids(self, plot_elements): """ Helper function to get the mpld4_id for each of the specified elements. """ mpld4_element_ids = [] # There are two things being done here. First, # we make sure that we have a list of lists, where # each inner list is associated with a single legend # item. Second, in case of Line2D object we pass # the id for both the marker and the line. # on the javascript side we filter out the nulls in # case either the line or the marker has no equivalent # D3 representation. for entry in plot_elements: ids = [] if isinstance(entry, collections.Iterable): for element in entry: mpld4_id = plugins.get_id(element) ids.append(mpld4_id) if isinstance(element, matplotlib.lines.Line2D): mpld4_id = plugins.get_id(element, 'pts') ids.append(mpld4_id) else: ids.append(plugins.get_id(entry)) if isinstance(entry, matplotlib.lines.Line2D): mpld4_id = plugins.get_id(entry, 'pts') ids.append(mpld4_id) mpld4_element_ids.append(ids) return mpld4_element_ids
def __init__(self, points, labels=None, targets=None, hoffset=2, voffset=-6, css=None): self.points = points self.labels = labels self.targets = targets self.voffset = voffset self.hoffset = hoffset self.css_ = css or "" if targets is not None: styled_targets = map(lambda x: self.css_ + x, targets) else: styled_targets = None if isinstance(points, matplotlib.lines.Line2D): suffix = "pts" else: suffix = None self.dict_ = { "type": "clickablehtmltooltip", "id": plugins.get_id(points, suffix), "labels": labels, "targets": styled_targets, "hoffset": hoffset, "voffset": voffset }
def __init__(self, points, button=True, enabled=True): if isinstance(points, matplotlib.lines.Line2D): suffix = "pts" else: suffix = None self.dict_ = { "type": "linkedbrush", "button": button, "enabled": enabled, "id": plugins.get_id(points, suffix) }
def __init__(self, line, label=None, hoffset=0, voffset=10, css=None): self.line = line self.label = label self.voffset = voffset self.hoffset = hoffset self.css_ = css or "" self.dict_ = { "type": "linehtmltooltip", "id": plugins.get_id(line), "label": label, "hoffset": hoffset, "voffset": voffset }
def __init__(self, points, labels=None, hoffset=0, voffset=10, css=None): self.points = points self.labels = labels self.voffset = voffset self.hoffset = hoffset self.css_ = css or "" if isinstance(points, matplotlib.lines.Line2D): suffix = "pts" else: suffix = None self.dict_ = { "type": "htmltooltip", "id": plugins.get_id(points, suffix), "labels": labels, "hoffset": hoffset, "voffset": voffset }
def __init__(self, points, label=None, hoffset=0, voffset=10, location="mouse"): if location not in [ "bottom left", "top left", "bottom right", "top right", "mouse" ]: raise ValueError("invalid location: {0}".format(location)) self.dict_ = { "type": "tooltip", "id": plugins.get_id(points), "labels": label if label is None else [label], "hoffset": hoffset, "voffset": voffset, "location": location }
def __init__(self, points, labels=None, hoffset=0, voffset=10, location="mouse"): if location not in [ "bottom left", "top left", "bottom right", "top right", "mouse" ]: raise ValueError("invalid location: {0}".format(location)) if isinstance(points, matplotlib.lines.Line2D): suffix = "pts" else: suffix = None self.dict_ = { "type": "tooltip", "id": plugins.get_id(points, suffix), "labels": labels, "hoffset": hoffset, "voffset": voffset, "location": location }
def __init__(self, plot_elements, labels, ax=None, alpha_sel=1, alpha_unsel=0.2, xoffset=0, yoffset=0, start_visible=False, fontsize=18): self.ax = ax if ax: ax = plugins.get_id(ax) # start_visible could be a list if isinstance(start_visible, bool): start_visible = [start_visible] * len(labels) elif not len(start_visible) == len(labels): raise ValueError("{} out of {} visible params has been set".format( len(start_visible), len(labels))) mpld4_element_ids = self._determine_mpld4ids(plot_elements) self.mpld4_element_ids = mpld4_element_ids self.dict_ = { "type": "interactive_legend", "element_ids": mpld4_element_ids, "labels": labels, "ax": ax, "alpha_sel": alpha_sel, "alpha_unsel": alpha_unsel, "xoffset": xoffset, "yoffset": yoffset, "start_visible": start_visible, "fontsize": fontsize }