• <i id='bAYUp'><tr id='bAYUp'><dt id='bAYUp'><q id='bAYUp'><span id='bAYUp'><b id='bAYUp'><form id='bAYUp'><ins id='bAYUp'></ins><ul id='bAYUp'></ul><sub id='bAYUp'></sub></form><legend id='bAYUp'></legend><bdo id='bAYUp'><pre id='bAYUp'><center id='bAYUp'></center></pre></bdo></b><th id='bAYUp'></th></span></q></dt></tr></i><div id='bAYUp'><tfoot id='bAYUp'></tfoot><dl id='bAYUp'><fieldset id='bAYUp'></fieldset></dl></div>
      <bdo id='bAYUp'></bdo><ul id='bAYUp'></ul>

    1. <small id='bAYUp'></small><noframes id='bAYUp'>

        <tfoot id='bAYUp'></tfoot>
      1. <legend id='bAYUp'><style id='bAYUp'><dir id='bAYUp'><q id='bAYUp'></q></dir></style></legend>

      2. 如何在谷歌协作笔记本中显示输出?

        时间:2023-09-28
        • <bdo id='6oIYU'></bdo><ul id='6oIYU'></ul>

            <tfoot id='6oIYU'></tfoot>
          1. <small id='6oIYU'></small><noframes id='6oIYU'>

            <legend id='6oIYU'><style id='6oIYU'><dir id='6oIYU'><q id='6oIYU'></q></dir></style></legend>

                <i id='6oIYU'><tr id='6oIYU'><dt id='6oIYU'><q id='6oIYU'><span id='6oIYU'><b id='6oIYU'><form id='6oIYU'><ins id='6oIYU'></ins><ul id='6oIYU'></ul><sub id='6oIYU'></sub></form><legend id='6oIYU'></legend><bdo id='6oIYU'><pre id='6oIYU'><center id='6oIYU'></center></pre></bdo></b><th id='6oIYU'></th></span></q></dt></tr></i><div id='6oIYU'><tfoot id='6oIYU'></tfoot><dl id='6oIYU'><fieldset id='6oIYU'></fieldset></dl></div>

                  <tbody id='6oIYU'></tbody>
                  本文介绍了如何在谷歌协作笔记本中显示输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我整天搜索如何在 google colaboratory jupyter notebooks 中显示绘图的输出.google colaboratory 有一个 stackoverflow 问题和官方教程,但它们都对我不起作用.

                  官方链接:
                  https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=hFCg8XrdO4xj

                  stackoverflow 问题:
                  Plotly notebook 模式与 google colaboratory
                  https://colab.research.google.com/drive/14oudHx5e5r7hm1QcbZ24FVHXgVPD0k8f#scrollTo=8RCjUVpi

                  内置 google colaboratory plotly 版本为 1.12.12.

                  测试情节版本

                  绘图导入情节.__版本__1.12.12

                  加载库

                  将 numpy 导入为 np将熊猫导入为 pd将 matplotlib.pyplot 导入为 plt将 seaborn 导入为 sns

                  安装谷歌驱动器

                  来自 google.colab 导入驱动器drive.mount('/content/drive')dat_dir = '驱动器/我的驱动器/Colab Notebooks/data/'

                  谷歌官方合作方法(失败)

                  # https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=hFCg8XrdO4xjdef enable_plotly_in_cell():导入 IPython从 plotly.offline 导入 init_notebook_mode显示(IPython.core.display.HTML('''<script src="/static/components/requirejs/require.js"></script>'''))init_notebook_mode(连接=假)

                  测试官方建议(失败)

                  import plotly.plotly as py将 numpy 导入为 np从 plotly.offline 导入 iplot从 plotly.graph_objs 导入 Contours、Histogram2dContour、Marker、Scatterenable_plotly_in_cell()x = np.random.randn(2000)y = np.random.randn(2000)iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))], show_link=False)

                  Stackoverflow Bob Smith 方法

                  # https://stackoverflow.com/questions/47230817/plotly-notebook-mode-with-google-colaboratorydef configure_plotly_browser_state():导入 IPython显示(IPython.core.display.HTML('''<script src="/static/components/requirejs/require.js"></script><脚本>需要js.config({路径:{基地:'/静态/基地',情节:'https://cdn.plot.ly/plotly-1.5.1.min.js?noext',},});</脚本>'''))

                  测试 Bob Smith 方法(失败)

                  # https://colab.research.google.com/drive/14oudHx5e5r7hm1QcbZ24FVHXgVPD0k8f#scrollTo=8RCjUVpi2_xd将 plotly.plotly 导入为 py将 numpy 导入为 np从 plotly.offline 导入 init_notebook_mode, iplot从 plotly.graph_objs 导入 Contours、Histogram2dContour、Marker、Scatterconfigure_plotly_browser_state()init_notebook_mode(连接=假)x = np.random.randn(2000)y = np.random.randn(2000)iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))], show_link=False)

                  问题

                  如何在 google colaboratory 中显示 plotly 输出?

                  有可能吗?如果是这样,哪个版本的 plotly 或 cufflinks 适合您?

                  如果无法显示,能否将输出文件保存为.html在我们的google drive中手动打开查看?

                  感谢您的帮助.

                  解决方案

                  plotly 4.x版

                  从版本 4 开始,plotly 渲染器了解 Colab,因此以下内容足以在 Colab 和 Jupyter(以及 Kaggle、Azure、nteract 等其他笔记本)中显示图形:

                  导入 plotly.graph_objectsfig = go.Figure(go.Scatter(x=[1,2,3], y=[1,3,2]) )图.show()

                  plotly 3.x 版

                  我也在努力在 Google colab 中显示绘图图表,并偶然发现了这个线程,您在其中解释了网络上不同解决方案的问题.每个解决方案的感觉都是相同的.最后,当我看到 这个视频时,我的搜索结束了.p>

                  我遵循了他的方法(可能与您已经尝试过的方法相似),这对我有用.

                  1. 按照建议通过 !pip install plotly --upgraderestart runtime 在 colab 中升级 plotly.
                  2. 评论升级选项,然后再重新运行您的笔记本
                  3. 定义函数configure_plotly_browser_state()
                  4. 调用 plotly 库
                  5. 在您要调用 iplot 的每个单元格中调用如下所示的函数和笔记本模式

                    configure_plotly_browser_state()

                    init_notebook_mode(connected=False)

                    iplot(XXXXXX)

                  只需导入 plotly 库

                  如果这有帮助,请告诉我:)

                  I searched whole day how to display the outputs of plotly plots in google colaboratory jupyter notebooks. There is a stackoverflow question and also official tutorial from google colaboratory but both of them did not work for me.

                  official link:
                  https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=hFCg8XrdO4xj

                  stackoverflow question:
                  Plotly notebook mode with google colaboratory
                  https://colab.research.google.com/drive/14oudHx5e5r7hm1QcbZ24FVHXgVPD0k8f#scrollTo=8RCjUVpi2_xd

                  The built-in google colaboratory plotly version is 1.12.12.

                  Test plotly version

                  import plotly
                  plotly.__version__
                  1.12.12
                  

                  Load libraries

                  import numpy as np
                  import pandas as pd
                  import matplotlib.pyplot as plt
                  import seaborn as sns
                  

                  Mount google drive

                  from google.colab import drive
                  drive.mount('/content/drive')
                  
                  dat_dir = 'drive/My Drive/Colab Notebooks/data/'
                  

                  Official google colaboratory method (FAILED)

                  # https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=hFCg8XrdO4xj
                  def enable_plotly_in_cell():
                    import IPython
                    from plotly.offline import init_notebook_mode
                    display(IPython.core.display.HTML('''
                          <script src="/static/components/requirejs/require.js"></script>
                    '''))
                    init_notebook_mode(connected=False)
                  

                  Test official suggestion (FAILED)

                  import plotly.plotly as py
                  import numpy as np
                  from plotly.offline import iplot
                  from plotly.graph_objs import Contours, Histogram2dContour, Marker, Scatter
                  
                  enable_plotly_in_cell()
                  
                  x = np.random.randn(2000)
                  y = np.random.randn(2000)
                  iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),
                         Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))], show_link=False)
                  

                  Stackoverflow Bob Smith Method

                  # https://stackoverflow.com/questions/47230817/plotly-notebook-mode-with-google-colaboratory
                  def configure_plotly_browser_state():
                    import IPython
                    display(IPython.core.display.HTML('''
                          <script src="/static/components/requirejs/require.js"></script>
                          <script>
                            requirejs.config({
                              paths: {
                                base: '/static/base',
                                plotly: 'https://cdn.plot.ly/plotly-1.5.1.min.js?noext',
                              },
                            });
                          </script>
                          '''))
                  

                  Test Bob Smith method (FAILED)

                  # https://colab.research.google.com/drive/14oudHx5e5r7hm1QcbZ24FVHXgVPD0k8f#scrollTo=8RCjUVpi2_xd
                  import plotly.plotly as py
                  import numpy as np
                  from plotly.offline import init_notebook_mode, iplot
                  from plotly.graph_objs import Contours, Histogram2dContour, Marker, Scatter
                  
                  configure_plotly_browser_state()
                  
                  init_notebook_mode(connected=False)
                  
                  x = np.random.randn(2000)
                  y = np.random.randn(2000)
                  iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),
                         Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))], show_link=False)
                  

                  Questions

                  How to display the plotly output in google colaboratory?

                  Is is possible ? If so which version of plotly or cufflinks is working for you?

                  If it is not possible to display, can we save the output file as .html in our google drive and open them manually and see them?

                  I appreciate your help.

                  解决方案

                  plotly version 4.x

                  As of version 4, plotly renderers know about Colab, so the following is sufficient to display a figure in both Colab and Jupyter (and other notebooks like Kaggle, Azure, nteract):

                  import plotly.graph_objects as go
                  fig = go.Figure( go.Scatter(x=[1,2,3], y=[1,3,2] ) )
                  fig.show()
                  

                  plotly version 3.x

                  I was also struggling to display the plotly graphs in Google colab and stumbled upon this thread where you explained the problems with different solutions over the net. Feelings are the same for each one of the solutions. Finally, my search ended when I came across this video.

                  I followed his approach (might be similar to the ones you already tried) and this worked for me.

                  1. Upgrade plotly in colab thru !pip install plotly --upgrade and restart runtime as suggested.
                  2. Comment the upgrade option before re-running your notebook
                  3. Define the function configure_plotly_browser_state()
                  4. Invoke plotly libraries
                  5. Call function and notebook mode like below in every cell where you want to call iplot

                    configure_plotly_browser_state()

                    init_notebook_mode(connected=False)

                    iplot(XXXXXX)

                  Just import plotly libraries

                  Please let me know if this helps :)

                  这篇关于如何在谷歌协作笔记本中显示输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Plotly:如何使用 Plotly Express 组合散点图和线图? 下一篇:Plotly:如何使用 Python 对绘图对象条形图进行颜色编码?

                  相关文章

                • <small id='BwqvP'></small><noframes id='BwqvP'>

                  <legend id='BwqvP'><style id='BwqvP'><dir id='BwqvP'><q id='BwqvP'></q></dir></style></legend>
                • <tfoot id='BwqvP'></tfoot>
                      <bdo id='BwqvP'></bdo><ul id='BwqvP'></ul>

                    1. <i id='BwqvP'><tr id='BwqvP'><dt id='BwqvP'><q id='BwqvP'><span id='BwqvP'><b id='BwqvP'><form id='BwqvP'><ins id='BwqvP'></ins><ul id='BwqvP'></ul><sub id='BwqvP'></sub></form><legend id='BwqvP'></legend><bdo id='BwqvP'><pre id='BwqvP'><center id='BwqvP'></center></pre></bdo></b><th id='BwqvP'></th></span></q></dt></tr></i><div id='BwqvP'><tfoot id='BwqvP'></tfoot><dl id='BwqvP'><fieldset id='BwqvP'></fieldset></dl></div>