python - 如何从 Google Colab 笔记本中的 gmplot draw 命令查看 html 输出文件?

标签 python google-colaboratory

我正在尝试使用 colab 和 googlemaps 来显示覆盖在 google map 上的热图图像。我做了一些研究,并在此链接上找到了 2 种可能的解决方案,但两种解决方案均无效。

Display / Render an HTML file inside Jupyter Notebook on Google Colab platform

也许最近发生了什么变化? 这是我的代码:

pip install gmplot
import gmplot 
gmap1 = gmplot.GoogleMapPlotter(30.3164945, 
                                78.03219179999999, 13, apikey='AIzaSyBCyhpxDYIxIq9uINYxDK5aIjWSokUvsvY' ) 
gmap1.draw( "map11.html" ) 
import os
print(os.getcwd())
!ls

/content
map11.html  sample_data

import IPython
IPython.display.HTML(filename='/content/map11.html')

nothing is displayed. 

from IPython.display import IFrame
IFrame(src='/content/map11.html', width=900, height=600)

localhost refused to connect.

enter image description here

最佳答案

您的本地浏览器无法从远程 VM 文件系统读取文件。不要通过文件名传递 HTML,而是尝试直接显示 HTML 内容:

IPython.display.HTML(open('/content/map11.html').read())

关于python - 如何从 Google Colab 笔记本中的 gmplot draw 命令查看 html 输出文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60814850/

相关文章:

python - 如何在 google colab 上使用 Box 2 D

Python负下标

python - 如何在不使用浏览器的情况下使用 Python 打开 URL?

python - cv2.VideoCapture 无法在 Mac 主机上的 docker 容器中工作

Python 3 列表的副作用?

jupyter-notebook - 如何解决 google colab 上没有名为 'nltk.translate.meteor_score' 的模块

google-colaboratory - 为什么即使使用 Colab Pro 帐户也无法连接到 GPU 后端?