Plotly Choropleth地图未显示在Google Colab中

发布于 2025-01-24 11:45:57 字数 444 浏览 5 评论 0原文

我一直在尝试通过Internet建议的每个解决方案,但它们似乎都不适合我。当我尝试在Colab中绘制绘图时,我要么获得一个空白页,要么是我的唱片地图的传奇/配色栏。有人可以帮我吗? 这是我尝试绘制的非常基本的代码。

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()

I have been trying every single solution that has been suggested over the Internet, but none of them seems to work for me. I get either a blank page or just the legend/colorbar for my choropleth map when I try to plot with Plotly in Colab. Can someone help me out with it?
Here is a very basic code that I try to plot.

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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烏雲後面有陽光 2025-01-31 11:45:57

我遇到了几个错误,并带有您可能已经看到的建议:

plotly Notebook Mode with Plotly Notebook模式Google合作制作

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

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>
            '''))

然后运行conduce> configure_plotly_browser_state()代码>在带有图show()的单元格中,

我知道不是一个美丽的解决方案,但希望它们为您服务。

I've encountered a couple of errors, with suggestions you may have seen:

Plotly notebook mode with google colaboratory

In particular these three possible fixes:

fig.show(renderer="colab")

Or by setting global default:

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

Finally, and unfortunately the possibility of having to set browser defaults in each cell by creating this function:

  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>
            '''))

And then running configure_plotly_browser_state() in the cell with fig.show()

Not a beautiful solution I know, but hopefully they work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文