使用地理坐标的三维绘图

2024-03-28 15:11:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像这样的数据集:

1 38.7114-7.92482 16.4375 0.2 ... 在

我想做一个三维散点图。我用笛卡尔坐标系做了。我怎么能用地理坐标来做呢?有什么提示吗?在

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import sys
from mpl_toolkits.basemap import Basemap

ID=[]
Latitude=[]
Longitude=[]
Depth=[]
cluster1='data1'
with open(cluster1) as f:
    lines = f.readlines()
    for line in lines:
        items = line.strip().split()
        lat = float(items[1])
        lon = float(items[2])
        dep = float(items[3])
        mag = float(items[4])
        Latitude.append(lat)
        Longitude.append(lon)
        Depth.append(dep)
        ID.append(mag)


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
p = ax.scatter(Longitude, Latitude, Depth, c=ID, marker='o')

ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.set_zlabel('Depth (km)')
ax.invert_zaxis()
cb = fig.colorbar(p,label='Magnitude')
plt.savefig('plot1.png')

enter image description here


Tags: fromimportidasfigitemspltax