使用地理坐标的3D绘图

时间:2016-08-22 16:37:22

标签: python matplotlib

我有一个如下所示的数据集:

1 38.7114 -7.92482 16.4375 0.2 ...

我想制作一个3D散点图。我用笛卡尔坐标完成了它。我如何使用地理坐标来做到这一点?任何提示?

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

0 个答案:

没有答案