python 在世界地图上绘制 GeoIP 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1565555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:35:48  来源:igfitidea点击:

Plot GeoIP data on a World Map

pythongeolocationmapsplot

提问by Unknown

I need a library (preferably written in Python) which is able to take a series of IP addresses (or geographic coordinates) and plots them on a World Map.

我需要一个库(最好用 Python 编写),它能够获取一系列 IP 地址(或地理坐标)并将它们绘制在世界地图上。

I already found this one, but it outputs data as a .svg file and it's simply unable to cope with large data sets.

我已经找到了这个,但是它将数据输出为 .svg 文件,它根本无法处理大型数据集。

Please note that I need something which can be downloaded and run locally, so no data uploading to 3rd party web services.

请注意,我需要一些可以在本地下载和运行的东西,所以没有数据上传到 3rd 方网络服务。

Thanks!

谢谢!

采纳答案by nazca

Perhaps Basemapin Matplotlibfor the plotting.

也许在Matplotlib中绘制底图

It can do all sorts of projections(don't mind the ugly default colours). And you have good control over what/how you plot. You can even use NASA Blue Marble imagery. And of course, you can plot markers, lines, etc on the map using the plot command.

它可以进行各种投影(不要介意丑陋的默认颜色)。而且您可以很好地控制您的绘图内容/方式。您甚至可以使用NASA Blue Marble 图像。当然,您可以使用 plot 命令在地图上绘制标记、线条等。

I haven't put huge datasets through it, but being that it is a part of Matplotlib I suspect it will do well.

我没有通过它放入大量数据集,但由于它是 Matplotlib 的一部分,我怀疑它会做得很好。

If I remember right, despite being part of the library, by default it doesn't ship with Matplotlib.

如果我没记错的话,尽管它是库的一部分,但默认情况下它不随 Matplotlib 一起提供。

回答by Martin Thoma

You might want to have a look at mapsplotlib.

你可能想看看mapsplotlib

Installation

安装

ONLY PYTHON 2.7!

只有 Python 2.7!

$ pip install mapsplotlib
$ pip install pandas

You'll then need to have a Google Static Maps API key, go to https://console.developers.google.com

然后您需要有一个 Google Static Maps API 密钥,请访问https://console.developers.google.com

Usage

用法

import pandas as pd
from mapsplotlib import mapsplot as mplt

df = pd.read_csv("data.csv")

mplt.register_api_key('your_google_api_key_here')
mplt.density_plot(df['latitude'], df['longitude'])

Example output

示例输出

enter image description here

在此处输入图片说明

回答by Corey Ballou

The google maps API can support all of the above if you would be willing to set up a local web environment for testing. There is a wrapper around the API for Python called pymaps.

如果您愿意设置本地网络环境进行测试,谷歌地图 API 可以支持上述所有内容。Python 的 API 有一个包装器,称为pymaps

The API documentation has an example on how to use Google's geocoder to plot points on a map given a particular input address:

API 文档有一个关于如何使用 Google 的地理编码器在给定特定输入地址的地图上绘制点的示例:

Google Maps API Example: Simple Geocoding

Google Maps API 示例:简单地理编码

回答by timgeb

I recently used gmplot.

我最近使用了gmplot.

Simply install it with

只需安装它

pip install gmplot

It is extremelyeasy to use. All you have to do is plug in the longitude and latitude values and gmplotwill put out a map in html-form.

非常易于使用。您所要做的就是插入经度和纬度值,然后gmplot以 html 格式输出地图。

Here's a minimal example. Let lat_valuesand lon_valuesbe lists of latitude and longitude values.

这是一个最小的例子。让lat_valueslon_values成为纬度和经度值的列表。

from gmplot import gmplot
import numpy as np

center_lat = np.mean(lat_values)
center_lon = np.mean(lon_values)
zoom = 15

gmap = gmplot.GoogleMapPlotter(center_lat, center_lon, zoom) 
gmap.scatter(lat_values, lon_values)
gmap.draw('my_map.html')

That's it! Of course, you can tune parameters to enhance the visuals. See the crash course here.

而已!当然,您可以调整参数以增强视觉效果。在此处查看速成课程