當前位置: 首頁>>代碼示例>>Python>>正文


Python offline.init_notebook_mode方法代碼示例

本文整理匯總了Python中plotly.offline.init_notebook_mode方法的典型用法代碼示例。如果您正苦於以下問題:Python offline.init_notebook_mode方法的具體用法?Python offline.init_notebook_mode怎麽用?Python offline.init_notebook_mode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在plotly.offline的用法示例。


在下文中一共展示了offline.init_notebook_mode方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _render

# 需要導入模塊: from plotly import offline [as 別名]
# 或者: from plotly.offline import init_notebook_mode [as 別名]
def _render(fig, showlegend=None):
    """Plot a matploltib or plotly figure"""
    if isinstance(fig, plt.Figure):
        fig = plotly.tools.mpl_to_plotly(fig, **PLOTLY_TO_MPL_KWS)

    if showlegend is not None:
        fig.layout["showlegend"] = showlegend

    if not IN_NOTEBOOK:
        message = "Lens explorer can only plot in a Jupyter notebook"
        logger.error(message)
        raise ValueError(message)
    else:
        if not py.offline.__PLOTLY_OFFLINE_INITIALIZED:
            py.init_notebook_mode()
        return py.iplot(fig, **PLOTLY_KWS) 
開發者ID:facultyai,項目名稱:lens,代碼行數:18,代碼來源:explorer.py

示例2: save_wordmesh_as_html

# 需要導入模塊: from plotly import offline [as 別名]
# 或者: from plotly.offline import init_notebook_mode [as 別名]
def save_wordmesh_as_html(self, coordinates, filename='temp-plot.html', 
                              animate=False, autozoom=True, notebook_mode=False):

        zoom = 1
        labels = ['default label']
        traces = []
        if animate:
            for i in range(coordinates.shape[0]):
                
                traces.append(self._get_trace(coordinates[i]))
                labels = list(map(str,range(coordinates.shape[0])))
                
        else:

            if autozoom:
                zoom = self._get_zoom(coordinates)
            traces = [self._get_trace(coordinates, zoom=zoom)]
            
        layout = self._get_layout(labels, zoom=zoom)
            
        fig = self.generate_figure(traces, labels, layout)
        
        if notebook_mode:
            py.init_notebook_mode(connected=True)
            py.iplot(fig, filename=filename, show_link=False)
        else:
            py.plot(fig, filename=filename, auto_open=False, show_link=False) 
開發者ID:mukund109,項目名稱:word-mesh,代碼行數:29,代碼來源:utils.py

示例3: enable_mpl_offline

# 需要導入模塊: from plotly import offline [as 別名]
# 或者: from plotly.offline import init_notebook_mode [as 別名]
def enable_mpl_offline(resize=False, strip_style=False,
                       verbose=False, show_link=True,
                       link_text='Export to plot.ly', validate=True):
    """
    Convert mpl plots to locally hosted HTML documents.

    This function should be used with the inline matplotlib backend
    that ships with IPython that can be enabled with `%pylab inline`
    or `%matplotlib inline`. This works by adding an HTML formatter
    for Figure objects; the existing SVG/PNG formatters will remain
    enabled.

    (idea taken from `mpld3._display.enable_notebook`)

    Example:
    ```
    from plotly.offline import enable_mpl_offline
    import matplotlib.pyplot as plt

    enable_mpl_offline()

    fig = plt.figure()
    x = [10, 15, 20, 25, 30]
    y = [100, 250, 200, 150, 300]
    plt.plot(x, y, "o")
    fig
    ```
    """
    init_notebook_mode()

    ip = IPython.core.getipython.get_ipython()
    formatter = ip.display_formatter.formatters['text/html']
    formatter.for_type(matplotlib.figure.Figure,
                       lambda fig: iplot_mpl(fig, resize, strip_style, verbose,
                                             show_link, link_text, validate)) 
開發者ID:jeanfeydy,項目名稱:lddmm-ot,代碼行數:37,代碼來源:offline.py

示例4: showTrace

# 需要導入模塊: from plotly import offline [as 別名]
# 或者: from plotly.offline import init_notebook_mode [as 別名]
def showTrace(trace, layout=None, title=None):
    """ Wrapper around Plotly's offline .plot() function

    Parameters
    ----------
    trace : plotly_trace
        Plotly generated trace to be displayed offline
    layout : plotly.graph_objs.Layout, optional
        Layout of plot to be displayed offline
    title : str, optional
        Title of plot to be displayed offline
    # colorize : bool, optional
    #     Toggles bw / colored plot [Default: True]

    Returns
    -------
    fig : plotly_fig_handle
        JSON representation of generated figure
    """
    if layout is None:
        layout = go.Layout(
            scene=dict(
                xaxis=dict(range=[-1, 1]),
                yaxis=dict(range=[-1, 1]),
                zaxis=dict(range=[-1, 1]),
                aspectmode='cube'
            )
        )
    # Wrap trace in array if needed
    if not isinstance(trace, list):
        trace = [trace]

    fig = go.Figure(
        data=trace,
        layout=layout
    )

    if title is not None:
        fig.layout.update(title=title)
        filename = f'{title}.html'
    else:
        try:
            filename = f'{fig.layout.title}.html'
        except TypeError:
            filename = f'{current_time()}.html'

    # if colorize:
    #    data[0].autocolorscale = False
    #    data[0].surfacecolor = [0, 0.5, 1]
    if env_info() == 'jupyter_notebook':
        plotly_off.init_notebook_mode()
        plotly_off.iplot(fig)
    else:
        plotly_off.plot(fig, filename=filename)

    return fig 
開發者ID:AppliedAcousticsChalmers,項目名稱:sound_field_analysis-py,代碼行數:58,代碼來源:plot.py


注:本文中的plotly.offline.init_notebook_mode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。