当前位置: 首页>>代码示例>>Python>>正文


Python plugins.connect函数代码示例

本文整理汇总了Python中mpld3.plugins.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    fig, ax = plt.subplots()
    points = ax.plot(range(10), 'o', ms=20)
    plugins.connect(fig, plugins.PointLabelTooltip(points[0],
                                                   location="top left"))

    return fig
开发者ID:Ahmed,项目名称:mpld3,代码行数:7,代码来源:test_plot_w_tooltips.py

示例2: main

def main():
    fig, ax = plt.subplots()
    line, = ax.plot([0, 1, 3, 8, 5], '-', lw=5)
    plugins.connect(fig, plugins.LineLabelTooltip(line, 'Line A'))
    ax.set_title('Line with Tooltip')

    return fig
开发者ID:JuergenNeubauer,项目名称:mpld3,代码行数:7,代码来源:test_plot_w_line_tooltips.py

示例3: main

def main():
    fig, ax = plt.subplots(2)

    # scatter periods and amplitudes
    np.random.seed(0)
    P = 0.2 + np.random.random(size=20)
    A = np.random.random(size=20)
    x = np.linspace(0, 10, 100)
    data = np.array([[x, Ai * np.sin(x / Pi)]
                     for (Ai, Pi) in zip(A, P)])
    points = ax[1].scatter(P, A, c=P + A,
                           s=200, alpha=0.5)
    ax[1].set_xlabel('Period')
    ax[1].set_ylabel('Amplitude')

    # create the line object
    lines = ax[0].plot(x, 0 * x, '-w', lw=3, alpha=0.5)
    ax[0].set_ylim(-1, 1)

    ax[0].set_title("Hover over points to see lines")

    # transpose line data and add plugin
    linedata = data.transpose(0, 2, 1).tolist()
    plugins.connect(fig, LinkedView(points, lines[0], linedata))

    return fig
开发者ID:JuergenNeubauer,项目名称:mpld3,代码行数:26,代码来源:test_custom_plugin.py

示例4: plot_snr_cmd

    def plot_snr_cmd(self, snr, ax, color='bv', mag='v', add_candidates=True):
        cmd_search = self.session.query(malchemy.MCPS).\
            join(malchemy.SNRNeighbour).join(malchemy.SNRS).\
            filter(malchemy.SNRS.id==snr.snr.id)

        cmd_data = [(item.__getattribute__(color[0]) -
                     item.__getattribute__(color[1]),
                     item.__getattribute__(mag)) for item in cmd_search]
        data = np.array(cmd_data)
        H, xedges, yedges = np.histogram2d(data[:,1], data[:,0], bins=100,
                                           range=[[16,22],[-1,2]])
        extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
        ax.imshow(H, extent=extent, interpolation='nearest',
                  cmap=cm.gray_r,
                  aspect='auto')

        ax.set_xlabel('Color {0} - {1}'.format(*list(color)))
        ax.set_ylabel('mag {0}'.format(mag))

        if add_candidates:
            candidate_coord = [(item.mcps.__getattribute__(color[0]) -
                     item.mcps.__getattribute__(color[1]),
                     item.mcps.__getattribute__(mag)) for item in snr.candidates]

            candidate_coord = np.array(candidate_coord)
            cand_plot = ax.plot(candidate_coord[:,0], candidate_coord[:,1], 'bo')
            cand_labels = [str(item) for item in snr.candidates]
            tooltip = plugins.PointHTMLTooltip(cand_plot[0], cand_labels,
                                   voffset=10, hoffset=10)

            plugins.connect(ax.figure, tooltip)



        return cand_plot
开发者ID:mhvk,项目名称:mcsnr,代码行数:35,代码来源:mcsnr_project.py

示例5: plot_xy_bootstrapped

def plot_xy_bootstrapped(xs, ys, thresholds, xlabel, ylabel, labels=False, labels_left=False, ax=None, fig=None, label=None, **plot_kwargs):
    if ax is None or fig is None:
        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()
开发者ID:ryninho,项目名称:topmodel,代码行数:28,代码来源:plot_helpers.py

示例6: generate_embedding

def generate_embedding(param_file, model_file, mnist_file, output_file=None,
                       param_key=None):
    predictor = optimus.load(model_file)
    params = biggie.Stash(param_file)
    param_key = sorted(params.keys())[-1] if param_key is None else param_key
    predictor.param_values = params.get(param_key)

    train, valid, test = datatools.load_mnist_npz(mnist_file)
    idx = np.random.permutation(len(valid[0]))[:2000]
    x_in = valid[0][idx]
    y_true = valid[1][idx]
    z_out = predictor(x_in=x_in)['z_out']

    imgfiles = [datatools.generate_imagename(i, y)
                for i, y in enumerate(idx, y_true)]

    labels = ['<img src="{}{}" width=100 height=100>'.format(URL_BASE, img)
              for img in imgfiles]

    palette = seaborn.color_palette("Set3", 10)
    colors = np.asarray([palette[y] for y in y_true])
    fig = plt.figure(figsize=(10, 10))
    ax = fig.gca()
    handle = ax.scatter(z_out.T[0], z_out.T[1],
                        c=colors, s=75, alpha=0.66)

    tooltip = plugins.PointHTMLTooltip(
        handle, labels,
        voffset=10, hoffset=10)

    plugins.connect(fig, tooltip)
    plt.show()
    if output_file:
        with open(output_file, 'w') as fp:
            mpld3.save_html(fig, fp)
开发者ID:ejhumphrey,项目名称:mnistifolds,代码行数:35,代码来源:visualize.py

示例7: create_plot

def create_plot():
    fig, ax = plt.subplots()
    line, = ax.plot([0, 1, 3, 8, 5], '-', lw=5)
    label = '<h1>Line {}</h1>'.format('A')
    plugins.connect(fig, plugins.LineHTMLTooltip(line, label))
    ax.set_title('Line with HTML Tooltip')
    return fig
开发者ID:2ciyuan,项目名称:mpld3,代码行数:7,代码来源:test_line_HTMLtooltips.py

示例8: doRender

    def doRender(self, handlerId):
        if self.canRenderChart(handlerId) == False:
            self._addHTML("Unable to find a numerical column in the dataframe")
            return

        mpld3.enable_notebook()
        fig, ax = plt.subplots()
        keyFields = self.getKeyFields(handlerId)
        keyFieldValues = self.getKeyFieldValues(handlerId, keyFields)
        keyFieldLabels = self.getKeyFieldLabels(handlerId, keyFields)
        valueFields = self.getValueFields(handlerId)
        valueFieldValues = self.getValueFieldValueLists(handlerId, keyFields, valueFields)
        context = self.getMpld3Context(handlerId)
        options = {"fieldNames":self.getFieldNames(),"aggregationSupported":self.supportsAggregation(handlerId),"aggregationOptions":["SUM","AVG","MIN","MAX","COUNT"]}
        if (context is not None):
            options.update(context[1])
            dialogBody = self.renderTemplate(context[0], **options)
        else:
            dialogBody = self.renderTemplate("baseChartOptionsDialogBody.html", **options)
        plugins.connect(fig, ChartPlugin(self, keyFieldLabels))
        plugins.connect(fig, DialogPlugin(self, handlerId, dialogBody))
        self.doRenderMpld3(handlerId, fig, ax, keyFields, keyFieldValues, keyFieldLabels, valueFields, valueFieldValues)
        self.setChartSize(handlerId, fig, ax)
        self.setChartGrid(handlerId, fig, ax)
        self.setChartLegend(handlerId, fig, ax)
开发者ID:ygoverdhan,项目名称:pixiedust,代码行数:25,代码来源:mpld3ChartDisplay.py

示例9: plot

    def plot(self, notebook=False, colormap='polar', scale=1, maptype='points', show=True, savename=None):

        # make a spatial map based on the scores
        fig = pyplot.figure(figsize=(12, 5))
        ax1 = pyplot.subplot2grid((2, 3), (0, 1), colspan=2, rowspan=2)
        if maptype is 'points':
            ax1, h1 = pointmap(self.scores, colormap=colormap, scale=scale, ax=ax1)
        elif maptype is 'image':
            ax1, h1 = imagemap(self.scores, colormap=colormap, scale=scale, ax=ax1)
        fig.add_axes(ax1)

        # make a scatter plot of sampled scores
        ax2 = pyplot.subplot2grid((2, 3), (1, 0))
        ax2, h2, samples = scatter(self.scores, colormap=colormap, scale=scale, thresh=0.01, nsamples=1000, ax=ax2, store=True)
        fig.add_axes(ax2)

        # make the line plot of reconstructions from principal components for the same samples
        ax3 = pyplot.subplot2grid((2, 3), (0, 0))
        ax3, h3, linedata = tsrecon(self.comps, samples, ax=ax3)

        plugins.connect(fig, LinkedView(h2, h3[0], linedata))
        plugins.connect(fig, HiddenAxes())

        if show and notebook is False:
            mpld3.show()

        if savename is not None:
            mpld3.save_html(fig, savename)
        elif show is False:
            return mpld3.fig_to_html(fig)
开发者ID:mathisonian,项目名称:thunder,代码行数:30,代码来源:pca.py

示例10: main

def main():
    fig, ax = plt.subplots()

    N = 50
    df = pd.DataFrame(index=range(N))
    df['x'] = np.random.randn(N)
    df['y'] = np.random.randn(N)
    df['z'] = np.random.randn(N)

    labels = []
    for i in range(N):
        label = df.ix[[i], :].T
        label.columns = ['Row {0}'.format(i)]
        labels.append(str(label.to_html()))  # .to_html() is unicode, so make leading 'u' go away with str()

    points = ax.plot(df.x, df.y, 'o', color='k', mec='w', ms=15, mew=1, alpha=.9)

    ax.set_xlabel('x')
    ax.set_ylabel('y')

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

    return fig
开发者ID:JuergenNeubauer,项目名称:mpld3,代码行数:25,代码来源:test_plot_w_html_tooltips.py

示例11: plot

    def plot(self, data, notebook=False, show=True, savename=None):

        fig = pyplot.figure()
        ncenters = len(self.centers)

        colorizer = Colorize()
        colorizer.get = lambda x: self.colors[int(self.predict(x)[0])]

        # plot time series of each center
        # TODO move into a time series plotting function in viz.plots
        for i, center in enumerate(self.centers):
            ax = pyplot.subplot2grid((ncenters, 3), (i, 0))
            ax.plot(center, color=self.colors[i], linewidth=5)
            fig.add_axes(ax)

        # make a scatter plot of the data
        ax2 = pyplot.subplot2grid((ncenters, 3), (0, 1), rowspan=ncenters, colspan=2)
        ax2, h2 = scatter(data, colormap=colorizer, ax=ax2)
        fig.add_axes(ax2)

        plugins.connect(fig, HiddenAxes())

        if show and notebook is False:
            mpld3.show()

        if savename is not None:
            mpld3.save_html(fig, savename)

        elif show is False:
            return mpld3.fig_to_html(fig)
开发者ID:uklibaite,项目名称:thunder,代码行数:30,代码来源:kmeans.py

示例12: __call__

    def __call__(self, plot, view):
        if not self._applies(plot, view): return
        fig = plot.handles['fig']
        if 'legend' in plot.handles:
            plot.handles['legend'].set_visible(False)
        line_segments, labels = [], []
        keys = view.keys()
        for idx, subplot in enumerate(plot.subplots.values()):
            if isinstance(subplot, PointPlot):
                line_segments.append(subplot.handles['paths'])
                if isinstance(view, NdOverlay):
                    labels.append(str(keys[idx]))
                else:
                    labels.append(subplot.map.last.label)
            elif isinstance(subplot, CurvePlot):
                line_segments.append(subplot.handles['line_segment'])
                if isinstance(view, NdOverlay):
                    labels.append(str(keys[idx]))
                else:
                    labels.append(subplot.map.last.label)

        tooltip = plugins.InteractiveLegendPlugin(line_segments, labels,
                                                  alpha_sel=self.alpha_sel,
                                                  alpha_unsel=self.alpha_unsel)
        plugins.connect(fig, tooltip)
开发者ID:aashish24,项目名称:holoviews,代码行数:25,代码来源:hooks.py

示例13: create_plot

def create_plot():
    fig, ax = plt.subplots()
    points = ax.scatter(np.random.rand(50), np.random.rand(50),
                        s=500, alpha=0.3)

    plugins.clear(fig)
    plugins.connect(fig, plugins.Reset(), plugins.Zoom(), ClickInfo(points))
    return fig
开发者ID:Bantalik,项目名称:mpld3,代码行数:8,代码来源:test_mouse_events.py

示例14: after

 def after(self):
     if self.draw:
         plugins.connect(
             self.fig, plugins.InteractiveLegendPlugin(
                 self.s1, self.labels, ax=self.ax))
         mpld3.show()
     else:
         pass
开发者ID:ssh0,项目名称:sotsuron,代码行数:8,代码来源:simple3.py

示例15: after

 def after(self):
     if self.draw:
         plugins.connect(
             self.fig, plugins.InteractiveLegendPlugin(
                 self.s1, self.labels, ax=self.ax))
         mpld3.display()
     else:
         print meeting.minutes
开发者ID:ssh0,项目名称:sotsuron,代码行数:8,代码来源:simple3_45.py


注:本文中的mpld3.plugins.connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。