在Python 3.6中从CSV绘制纬度经度 [英] Plot latitude longitude from CSV in Python 3.6

查看:158
本文介绍了在Python 3.6中从CSV绘制纬度经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从地图上的CSV文件绘制大量的纬度经度值,并采用这种格式(第一列和第二列):

I'm trying to plot a large number of latitude longitude values from a CSV file on a map, having this format (first column and second column):

我正在使用python 3.6(显然,某些库(例如Basemap不适用于此版本)).

I'm using python 3.6 (apparently some libraries like Basemap doesn't operate on this version).

我该怎么做?

推荐答案

如果您只是想将点数据绘制为散点图,就很简单

If you are just looking at plotting the point data as a scatterplot, is as simple as

import matplotlib.pyplot as plt
plt.scatter(x=df['Longitude'], y=df['Latitude'])
plt.show()

如果您想在地图上绘制点,它会变得越来越有趣,因为它更多地取决于您如何绘制地图.

If you want to plot the points on the map, it's getting interesting because it depends more on how you plot your map.

一种简单的方法是使用shapelygeopandas.鉴于我目前在使用的笔记本电脑上的访问权限有限,因此未对以下代码进行测试,但这应该为您提供概念上的路线图.

A simple way is to use shapely and geopandas. The code below is not tested given my limited access on the laptop I am currently using, but it should give you a conceptual roadmap.

from shapely.geometry import Point
import geopandas as gpd
from geopandas import GeoDataFrame

df = pd.read_csv("Long_Lats.csv", delimiter=',', skiprows=0, low_memory=False)

geometry = [Point(xy) for xy in zip(df['Longitude'], df['Latitude'])]
gdf = GeoDataFrame(df, geometry=geometry)   

#this is a simple map that goes with geopandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf.plot(ax=world.plot(figsize=(10, 6)), marker='o', color='red', markersize=15);

在渲染图像的示例下查找:

Find below an example of the rendered image:

这篇关于在Python 3.6中从CSV绘制纬度经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆