繁体   English   中英

Plotly choropleth 地图未在 Google Colab 中显示

[英]Plotly choropleth map not showing in Google Colab

我一直在尝试互联网上建议的每一个解决方案,但它们似乎都不适合我。 当我尝试在 Colab 中使用 Plotly 进行绘图时,我得到一个空白页或只是我的 choropleth 地图的图例/颜色条。 有人可以帮我解决吗? 这是我尝试绘制的非常基本的代码。

import plotly.express as px
fig = px.choropleth(gdf,
                    locations="id",
                    geojson=geojson,
                    color="Total - Visible minority",
                    scope="north america",
                    projection="conic conformal"
                    )
fig.show()

我遇到了几个错误,您可能已经看到了一些建议:

Plotly 与谷歌合作的笔记本模式

特别是这三个可能的修复:

fig.show(renderer="colab")

或者通过设置全局默认值:

import plotly.io as pi
pio.renderers.default = "colab"

最后,不幸的是,必须通过创建此函数在每个单元格中设置浏览器默认值:

  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-latest.min.js?noext',
                },
              });
            </script>
            '''))

然后使用fig.show()在单元格中运行configure_plotly_browser_state() )

我知道这不是一个漂亮的解决方案,但希望它们对你有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM