[英]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()
我遇到了幾個錯誤,您可能已經看到了一些建議:
特別是這三個可能的修復:
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.